using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Data.SqlClient;
using System.Globalization;
using System.Linq;
using System.Windows.Forms;
using EbmtDAL.Custom_Controls;
using EbmtDAL.DataSets;
using EbmtDAL.DataSets.dsEbmtDbInfoTableAdapters;
using EbmtDAL.Properties;

namespace EbmtDAL
{
    /// <summary>
    ///   Provides methods to work with the EBMT data.
    /// </summary>
    public static class EbmtDAL
    {
        #region local members

        private static string dataCreationReport = "";
        internal static String currentEbmtDbConnectionString;
        private static SqlConnection mySqlConnection;
        private static readonly dsEbmtDbInfo myDsEbmtInfo = new dsEbmtDbInfo();
        private static readonly BindingSource bsEBMTColumnsList = new BindingSource();
        private static readonly BindingSource bsEBMTPKeyColUsageList = new BindingSource();
        private static readonly BindingSource bsEBMTFKeyColUsageList = new BindingSource();
        private static readonly BindingSource bsEbmtRelationsList = new BindingSource();
        private static readonly DataSet myEBMTDataSet = new DataSet("GenericEBMTDataSet");
        private static readonly List<EbmtDataAdapter> dataAdaptersList = new List<EbmtDataAdapter>();
        private static readonly EbmtTablesListTableAdapter taEbmtTablesList = new EbmtTablesListTableAdapter();
        private static readonly EbmtColumnsListTableAdapter taEbmtColumnsList = new EbmtColumnsListTableAdapter();

        private static readonly EbmtPKeyColUsageListTableAdapter taEbmtPKeyColUsageList =
            new EbmtPKeyColUsageListTableAdapter();

        private static readonly EbmtFKeyColUsageListTableAdapter taEbmtFKeyColUsageList =
            new EbmtFKeyColUsageListTableAdapter();

        private static readonly EbmtRelationsListTableAdapter taEbmtRelationsList = new EbmtRelationsListTableAdapter();

        //EBMT Tables Dataviews
        public static List<ExBindingSource> binSourcesCollection = new List<ExBindingSource>();
        //EBMT recordsSelections kept in memory.
        public static List<RecordSelectionMem> recordsSelectionsList = new List<RecordSelectionMem>();

        #endregion

        /// <summary>
        ///   Set the current database ebmt connection string.
        /// </summary>
        /// <param name="cString"> </param>
        public static void SetCurrentEbmtDbConnectionString(String cString)
        {
            currentEbmtDbConnectionString = cString;
        }

        #region Generic EBMT dataset generation

        // This region contains the generic methods used to create an EBMT dataset 
        // completely independant of the current structure of the EBMT database.
        // If a table name was changed or a new field was added to any table, these methods
        // will take automatically into account those changes and will create the dataset
        // objects conform to the new structure.

        /// <summary>
        ///   Load the information about the tables, columns, pkey, fkeys of the EBMT database. and stores all this information into the dsEbmtDbInfo dataset.
        /// </summary>
        public static void LoadEBMTInformationData()
        {
            mySqlConnection = new SqlConnection(currentEbmtDbConnectionString);
            taEbmtTablesList.Connection = mySqlConnection;
            taEbmtColumnsList.Connection = mySqlConnection;
            taEbmtPKeyColUsageList.Connection = mySqlConnection;
            taEbmtFKeyColUsageList.Connection = mySqlConnection;
            taEbmtRelationsList.Connection = mySqlConnection;

            taEbmtTablesList.Fill(myDsEbmtInfo.EbmtTablesList);
            taEbmtColumnsList.Fill(myDsEbmtInfo.EbmtColumnsList);
            taEbmtPKeyColUsageList.Fill(myDsEbmtInfo.EbmtPKeyColUsageList);
            taEbmtFKeyColUsageList.Fill(myDsEbmtInfo.EbmtFKeyColUsageList);
            taEbmtRelationsList.Fill(myDsEbmtInfo.EbmtRelationsList);
            bsEBMTColumnsList.DataSource = myDsEbmtInfo.EbmtColumnsList;
            bsEBMTPKeyColUsageList.DataSource = bsEBMTColumnsList;
            bsEBMTPKeyColUsageList.DataMember = "EbmtColumnsList_EbmtKeyColUsageList";
        }

        /// <summary>
        ///   Create the tables from the tables list read from sys.tables of the EBMT database. Create the columns, pkeys and fkeys for each of those tables. Creates the EbmtDataAdapter objects for each of those tables. It writes a report of the data objects creation.
        /// </summary>
        public static void CreateTablesIntoEbmtDataset()
        {
            foreach (dsEbmtDbInfo.EbmtTablesListRow rTable in myDsEbmtInfo.EbmtTablesList.Rows)
            {
                DataTable dTable = GetEbmtDataTable(rTable.name);
                if (dTable != null)
                {
                    myEBMTDataSet.Tables.Add(dTable);
                    dataCreationReport = dataCreationReport + "Table Added:" + dTable.TableName + "\n";
                }
                CreateTablePrimaryAndForeignKeys(rTable.name);
                EbmtDataAdapter ebmtDataAdapter = GetEbmtDataAdapter(rTable.name);
                if (ebmtDataAdapter != null)
                {
                    dataAdaptersList.Add(ebmtDataAdapter);
                }
            }
        }

        /// <summary>
        ///   Loads the patient data into the EBMT dataset. This is the generic version of this method.
        /// </summary>
        /// <param name="ID"> The Center's ID for whom we fill the data. </param>
        /// <param name="IDAA"> The patient's IDAA for whom we fill the data. </param>
        /// <returns> A filled EBMT dataset. </returns>
        public static DataSet LoadPatientData(int ID, int IDAA)
        {
            //If the EBMT dataset contains already any table we just need to
            //clear any data into it before filling new data.
            if (myEBMTDataSet.Tables.Count == 0)
            {
                //We load the EBMT structure information in order to create
                //all the tables and relationships into the dataset.
                LoadEBMTInformationData();
                CreateTablesIntoEbmtDataset();
            }
            else
            {
                //We clear any data already into the dataset.
                myEBMTDataSet.Clear();
            }
            try
            {
                foreach (EbmtDataAdapter taAdapter in dataAdaptersList)
                {
                    if (taAdapter.IdIdaaKeysExist)
                    {
                        taAdapter.FillByIDIDAA(myEBMTDataSet.Tables[taAdapter.TableName], ID, IDAA);
                    }
                    else
                    {
                        taAdapter.Fill(myEBMTDataSet.Tables[taAdapter.TableName]);
                    }
                }
                return myEBMTDataSet;
            }
            catch (SqlException)
            {
                return null;
            }
        }

        /// <summary>
        ///   Maps the SQL data types to the System data types.
        /// </summary>
        /// <param name="SqlTypeName"> </param>
        /// <returns> A system data type </returns>
        public static Type GetSystemDataType(string SqlTypeName)
        {
            switch (SqlTypeName)
            {
                case "bigint":
                    return typeof (Int64);
                case "binary":
                    return typeof (Byte[]);
                case "bit":
                    return typeof (Boolean);
                case "char":
                    return typeof (String);
                case "date":
                    return typeof (DateTime);
                case "datetime":
                    return typeof (DateTime);
                case "datetime2":
                    return typeof (DateTime);
                case "datetimeoffset":
                    return typeof (DateTimeOffset);
                case "decimal":
                    return typeof (Decimal);
                case "float":
                    return typeof (Double);
                case "image":
                    return typeof (Byte[]);
                case "int":
                    return typeof (Int32);
                case "money":
                    return typeof (Decimal);
                case "nchar":
                    return typeof (String);
                case "ntext":
                    return typeof (String);
                case "numeric":
                    return typeof (Decimal);
                case "nvarchar":
                    return typeof (String);
                case "real":
                    return typeof (Single);
                case "rowversion":
                    return typeof (Byte);
                case "smalldatetime":
                    return typeof (DateTime);
                case "smallint":
                    return typeof (Int16);
                case "smallmoney":
                    return typeof (Decimal);
                case "sql_variant":
                    return typeof (Object);
                case "text":
                    return typeof (String);
                case "time":
                    return typeof (TimeSpan);
                case "timestamp":
                    return typeof (Byte);
                case "tinyint":
                    return typeof (Byte);
                case "uniqueidentifier":
                    return typeof (Guid);
                case "varbinary":
                    return typeof (Byte[]);
                case "varchar":
                    return typeof (String);
                default:
                    throw new Exception("Unknown or not supported data type." +
                                        "Please verify the data type or configure the program in order to support it.");
            }
        }

        /// <summary>
        ///   Build the DataTable using the information loaded from the database.
        /// </summary>
        /// <param name="tableName"> </param>
        /// <returns> A DataTable object. </returns>
        public static DataTable GetEbmtDataTable(string tableName)
        {
            DataTable ebmtDataTable = new DataTable(tableName);
            bsEBMTColumnsList.Filter = "TABLE_NAME='" + tableName + "'";
            ebmtDataTable.TableName = tableName.Replace(" ", "_");
            if (bsEBMTColumnsList.Count > 0)
            {
                foreach (object t in bsEBMTColumnsList)
                {
                    DataRowView dRView = (DataRowView) t;
                    string dsColumnName = dRView["COLUMN_NAME"].ToString().Replace(" ", "_");
                    DataColumn newColumn = new DataColumn(dsColumnName);
                    newColumn.DataType = GetSystemDataType(dRView["DATA_TYPE"].ToString());
                    ebmtDataTable.Columns.Add(newColumn);
                }
                return ebmtDataTable;
            }
            return null;
        }

        /// <summary>
        ///   Build the PK and FK using the information loaded from the database.
        /// </summary>
        /// <param name="tableName"> The name of the Datatable object into the EBMT dataset. </param>
        public static void CreateTablePrimaryAndForeignKeys(string tableName)
        {
            string ebmtTableName = tableName.Replace(" ", "_");
            if (myEBMTDataSet.Tables.Contains(ebmtTableName))
            {
                bsEBMTPKeyColUsageList.Filter = "TABLE_NAME='" + tableName + "'";

                DataTable ebmtDataTable = myEBMTDataSet.Tables[ebmtTableName];
                List<DataColumn> pKeyColumns = new List<DataColumn>();
                if (bsEBMTColumnsList.Count > 0)
                {
                    foreach (object t in bsEBMTPKeyColUsageList)
                    {
                        DataRowView dRView = (DataRowView) t;
                        string dsColumnName = dRView["COLUMN_NAME"].ToString().Replace(" ", "_");
                        pKeyColumns.Add(ebmtDataTable.Columns[dsColumnName]);
                    }
                }
                if (pKeyColumns.Count > 0)
                {
                    ebmtDataTable.PrimaryKey = pKeyColumns.ToArray<DataColumn>();
                }

                bsEbmtRelationsList.Filter = "TABLE_NAME='" + tableName + "'";
                if (bsEbmtRelationsList.Count > 0)
                {
                    DataRowView dRelView = (DataRowView) bsEbmtRelationsList[0];
                    bsEBMTFKeyColUsageList.Filter = "TABLE_NAME='" + tableName + "' AND '" + dRelView["CONSTRAINT_NAME"] +
                                                    "'";
                    List<DataColumn> fKeyColumns = new List<DataColumn>();
                    if (bsEBMTFKeyColUsageList.Count > 0)
                    {
                        foreach (object t in bsEBMTPKeyColUsageList)
                        {
                            DataRowView dRView = (DataRowView) t;
                            string dsColumnName = dRView["COLUMN_NAME"].ToString().Replace(" ", "_");
                            fKeyColumns.Add(ebmtDataTable.Columns[dsColumnName]);
                        }
                    }
                    if (fKeyColumns.Count > 0)
                    {
                        ebmtDataTable.Constraints.Add(dRelView["CONSTRAINT_NAME"].ToString(),
                                                      pKeyColumns.ToArray<DataColumn>(),
                                                      fKeyColumns.ToArray<DataColumn>());
                    }
                }
            }
        }

        /// <summary>
        ///   Generates the EBMTDataAdapter of the table, using the information loaded from the database. The dataadapter will contain a generic Fill method in order to fill all the columns of the Table, and if the ID,IDAA columns exist it will contain a FillByIDIDAA method.
        /// </summary>
        /// <param name="tableName"> </param>
        /// <returns> A EbmtDataAdapter object; </returns>
        public static EbmtDataAdapter GetEbmtDataAdapter(string tableName)
        {
            bool idIdaaKeysExist = false;
            bsEBMTColumnsList.Filter = "TABLE_NAME='" + tableName + "'";

            if (bsEBMTColumnsList.Count > 0)
            {
                SqlDataAdapter myNewDataAdapter = new SqlDataAdapter();
                SqlCommand[] myCommandCollection = new SqlCommand[2];
                DataTableMapping tableMapping = new DataTableMapping();
                tableMapping.SourceTable = tableName;
                tableMapping.DataSetTable = tableName.Replace(" ", "_");

                string selectCommandText = "SELECT";
                for (int i = 0; i < bsEBMTColumnsList.Count; i++)
                {
                    DataRowView dRView = (DataRowView) bsEBMTColumnsList[i];
                    string origColumnName = dRView["COLUMN_NAME"].ToString();
                    string dsColumnName = dRView["COLUMN_NAME"].ToString().Replace(" ", "_");
                    //We test to know if identifiers exist.
                    if (dsColumnName == "IDAA")
                    {
                        idIdaaKeysExist = true;
                    }
                    //We add the column mapping to the table mapping object.
                    tableMapping.ColumnMappings.Add(origColumnName, dsColumnName);
                    selectCommandText = selectCommandText + " " + origColumnName + ",";
                    if (i == bsEBMTColumnsList.Count - 1)
                    {
                        selectCommandText = selectCommandText + " " + origColumnName + " FROM " + tableName;
                    }
                }
                myNewDataAdapter.TableMappings.Add(tableMapping);
                myCommandCollection[0] = new SqlCommand();
                myCommandCollection[1] = new SqlCommand();
                myCommandCollection[0].CommandText = selectCommandText;
                myCommandCollection[0].Connection = mySqlConnection;
                if (idIdaaKeysExist)
                {
                    myCommandCollection[1].CommandText = selectCommandText + " WHERE (ID = @ID) AND (IDAA = @IDAA)";
                    myCommandCollection[1].Parameters.Add(new SqlParameter("@ID",
                                                                           SqlDbType.
                                                                               Int, 4,
                                                                           ParameterDirection
                                                                               .Input, 0,
                                                                           0, "ID",
                                                                           DataRowVersion
                                                                               .Current,
                                                                           false, null, "",
                                                                           "", ""));
                    myCommandCollection[1].Parameters.Add(new SqlParameter("@IDAA",
                                                                           SqlDbType.
                                                                               Int, 4,
                                                                           ParameterDirection
                                                                               .Input, 0,
                                                                           0, "IDAA",
                                                                           DataRowVersion
                                                                               .Current,
                                                                           false, null, "",
                                                                           "", ""));
                    myCommandCollection[1].Connection = mySqlConnection;
                    myNewDataAdapter.SelectCommand = myCommandCollection[1];
                }
                else
                {
                    myNewDataAdapter.SelectCommand = myCommandCollection[0];
                }
                EbmtDataAdapter myNewEbmtDataAdapter = new EbmtDataAdapter(myNewDataAdapter, myCommandCollection);
                myNewEbmtDataAdapter.TableName = tableName;
                myNewEbmtDataAdapter.IdIdaaKeysExist = idIdaaKeysExist;
                return myNewEbmtDataAdapter;
            }
            return null;
        }

        #endregion

        #region Filtering and selection of EBMT data.

        /// <summary>
        ///   Initializes the Generic BindingSources contained on the binSourcesCollection Collection. and initializes the relationships between each parent bs and the child bs.
        /// </summary>
        public static void InitializePatientDataBindingSourcesG(DataSet dsEbmtPatientG)
        {
            foreach (DataTable dTable in dsEbmtPatientG.Tables)
            {
                ExBindingSource currentExBinSource = new ExBindingSource("bs" + dTable.TableName);
                currentExBinSource.DataSource = dTable;
                if (!binSourcesCollection.Contains(currentExBinSource))
                {
                    binSourcesCollection.Add(currentExBinSource);
                }
                if (dTable.ChildRelations.Count > 0)
                {
                    foreach (DataRelation dRelation in dTable.ChildRelations)
                    {
                        ExBindingSource currentExBinSource2 = new ExBindingSource("bs" + dRelation.ChildTable);
                        currentExBinSource2.DataSource = currentExBinSource;
                        currentExBinSource2.DataMember = "FK_" + dTable.TableName + "_" + dRelation.ChildTable;
                    }
                }
            }
        }

        public static void ResetBindingSourcesRowFiltersG()
        {
            if (binSourcesCollection.Count > 0)
            {
                foreach (ExBindingSource currentExBinSource in binSourcesCollection)
                {
                    currentExBinSource.isRecordFiltered = false;
                    currentExBinSource.Filter = "";
                }
            }
        }

        public static ExBindingSource GetExBindingSourceByTableName(String tableName)
        {
            ExBindingSource binSource2Find = new ExBindingSource("bs" + tableName);
            if (binSourcesCollection.Contains(binSource2Find))
            {
                int bsIndex = binSourcesCollection.IndexOf(binSource2Find);
                ExBindingSource currentExBinSource = binSourcesCollection.ElementAt(bsIndex);
                return currentExBinSource;
            }
            return null;
        }

        public static DataSet ApplyRecordsSelectionG2(DataSet dsMappingInfo, String recordsSelectionID,
                                                      int repeatingSequenceNumber, DateTime dateOfTransplant)
        {
            if (recordsSelectionID != "")
            {
                DataView recordsSelFunctions = new DataView(dsMappingInfo.Tables["RecordsSelectionFunctions"]);
                recordsSelFunctions.RowFilter = "[EBMT Selections ID]='" + recordsSelectionID + "'";

                DataView recordsSelectionExpressions = new DataView(dsMappingInfo.Tables["RecordsSelection"]);
                recordsSelectionExpressions.RowFilter = "[EBMT Selections ID]='" + recordsSelectionID + "'";


                if (recordsSelFunctions.Count > 0)
                {
                    //If we have functions for this definition it means that this definition 
                    //doesn't fit the record selection pattern.
                    //We retrieve the subset of data from the function result.
                    DataSet dsTemp = ApplyRecSelectionFunctionsG2(dsMappingInfo, recordsSelectionID,
                                                                  repeatingSequenceNumber, dateOfTransplant);

                    if (recordsSelectionExpressions.Count > 0)
                    {
                        //We apply the record selection pattern applying the expressions 
                        //and filtering our resulting subset of data.
                        dsTemp.Merge(ApplyRecSelectionExpressionsG2(recordsSelectionID, dsMappingInfo));
                    }
                    return dsTemp;
                }
                if (recordsSelectionExpressions.Count > 0)
                {
                    //We apply the record selection pattern applying the expressions 
                    //and filtering our resulting subset of data.
                    return ApplyRecSelectionExpressionsG2(recordsSelectionID, dsMappingInfo);
                }
                throw new Exception("The Selection ID specified doesn't have any function or expression.");
            }
            throw new Exception("The selection ID specified is not valid (empty text).");
        }

        internal static Boolean IsExBindingSourceOnList(List<ExBindingSource> binSourcesCollection,
                                                        ExBindingSource bsToFilter)
        {
            return binSourcesCollection.Contains(bsToFilter);
        }

        internal static DataSet ApplyRecSelectionExpressionsG2(String recordsSelectionID, DataSet dsMappingInfo)
        {
            DataView recordsSelectionExpressions = new DataView(dsMappingInfo.Tables["RecordsSelectionFilters"]);
            recordsSelectionExpressions.RowFilter = "[EBMT Selections ID]='" + recordsSelectionID + "'";
            DataView rSelTablesCounter = new DataView(dsMappingInfo.Tables["RSelTablesCounter"]);
            rSelTablesCounter.RowFilter = "[EBMT Selections ID]='" + recordsSelectionID + "'";
            if (recordsSelectionExpressions.Count > 0)
            {
                TableFilter[] tfilters = new TableFilter[recordsSelectionExpressions.Count];

                for (int i = 0; i <= recordsSelectionExpressions.Count - 1; i++)
                {
                    DataRowView rFilterRowView = recordsSelectionExpressions[i];
                    DataRow filterRow = rFilterRowView.Row;
                    tfilters[i].TableName = filterRow["EBMT_Sel_Table_ID"].ToString();
                    tfilters[i].RowsFilter = filterRow["FilterText"].ToString();
                }
                for (int i = 0; i <= tfilters.Length - 1; i++)
                {
                    if (tfilters[i].RowsFilter != "")
                    {
                        ExBindingSource bsToFilter = new ExBindingSource("bs" + tfilters[i].TableName);

                        if (IsExBindingSourceOnList(binSourcesCollection, bsToFilter))
                        {
                            int bsIndex = binSourcesCollection.IndexOf(bsToFilter);
                            ExBindingSource currentExBinSource = binSourcesCollection.ElementAt(bsIndex);
                            currentExBinSource.Filter = tfilters[i].RowsFilter;
                        }
                        else
                        {
                            //The name of the binding source object provided was not found
                            //in the collection bsToFilter.
                            throw new Exception("The name of the binding source object provided was not found " +
                                                "in the collection bsToFilter.");
                        }
                    }
                }
                return GetFilteredEBMTDataSetG2(tfilters);
            }
            return null;
        }

        internal static DataSet ApplyRecSelectionFunctionsG2(DataSet dsMappingInfo, String recordsSelectionID,
                                                             int repeatingSequenceNumber, DateTime dateOfTransplant)
        {
            DataSet resultDataSet = new DataSet();
            resultDataSet.EnforceConstraints = false;
            DataView recordsSelFunctions = new DataView(dsMappingInfo.Tables["RecordsSelectionFunctions"]);
            recordsSelFunctions.RowFilter = "[EBMT Selections ID]='" + recordsSelectionID + "'";

            if (recordsSelectionID == "S2450-1-071")
            {
            }
            if (recordsSelFunctions.Count > 0)
            {
                TableFilter[] tfilters = new TableFilter[recordsSelFunctions.Count];

                for (int i = 0; i <= recordsSelFunctions.Count - 1; i++)
                {
                    DataRowView rFunctionRowView = recordsSelFunctions[i];
                    DataRow functionRow = rFunctionRowView.Row;
                    tfilters[i] = new TableFilter();
                    tfilters[i].TableName = (string) functionRow["EBMT Sel Table ID"];
                    tfilters[i].FilterText = (string) functionRow["EBMT RecFilter"];

                    ExBindingSource tempExBinSource = new ExBindingSource("bs" + functionRow["EBMT Sel Table ID"]);
                    if (binSourcesCollection.Contains(tempExBinSource))
                    {
                        int bsIndex = binSourcesCollection.IndexOf(tempExBinSource);
                        ExBindingSource tempExBinSource2 = binSourcesCollection.ElementAt(bsIndex);
                        tempExBinSource2.isRecordFiltered = true;
                        DataRow[] dRows;
                        RecordSelectionMem tempRecSelObj = new RecordSelectionMem(recordsSelectionID, null);
                        if (recordsSelectionsList.Contains(tempRecSelObj))
                        {
                            RecordSelectionMem backedUpRecSelection =
                                recordsSelectionsList[recordsSelectionsList.IndexOf(tempRecSelObj)];
                            dRows = backedUpRecSelection.ResultingRows;
                        }
                        else
                        {
                            dRows = GetFunctionResultingRows(tempExBinSource2, functionRow, repeatingSequenceNumber,
                                                             dateOfTransplant);
                            RecordSelectionMem backedUpRecSelection = new RecordSelectionMem(recordsSelectionID, dRows);
                            recordsSelectionsList.Add(backedUpRecSelection);
                        }
                        if (dRows != null)
                        {
                            resultDataSet.Merge(dRows);
                        }
                    }
                    else
                    {
                        //The name of the binding source object provided was not found
                        //in the collection tempExBinSource.
                        throw new Exception("The name of the binding source object provided was not found " +
                                            "in the collection tempExBinSource.");
                    }
                }
                return resultDataSet.Tables.Count > 0 ? GetFilteredEBMTDataSetG2(resultDataSet, tfilters) : resultDataSet;
            }
            return resultDataSet;
        }

        public static DataSet GetFilteredEBMTDataSetG2(TableFilter[] tFilters)
        {
            DataSet resultDataSet = new DataSet();
            //resultDataSet.Merge(dsEbmtPatient.AA_);
            resultDataSet.EnforceConstraints = false;


            for (int i = 0; i <= tFilters.Length - 1; i++)
            {
                ExBindingSource tempExBinSource = new ExBindingSource("bs" + tFilters[i].TableName);
                if (binSourcesCollection.Contains(tempExBinSource))
                {
                    int bsIndex = binSourcesCollection.IndexOf(tempExBinSource);
                    ExBindingSource tempExBinSource2 = binSourcesCollection.ElementAt(bsIndex);
                    tempExBinSource2.isRecordFiltered = true;
                    DataRow[] dRows = GetSelectedDataRows(tempExBinSource2, tFilters[i]);
                    if (dRows != null)
                    {
                        resultDataSet.Merge(dRows);
                    }
                }
                else
                {
                    //The name of the binding source object provided was not found
                    //in the collection tempExBinSource.
                    throw new Exception("The name of the binding source object provided was not found " +
                                        "in the collection tempExBinSource.");
                }
            }
            return resultDataSet;
        }

        public static DataSet GetFilteredEBMTDataSetG2(DataSet dsTemp, TableFilter[] tFilters)
        {
            DataSet resultDataSet = new DataSet();
            resultDataSet.EnforceConstraints = false;

            for (int i = 0; i <= tFilters.Length - 1; i++)
            {
                DataRow[] dRows = GetSelectedDataRows(dsTemp.Tables[tFilters[i].TableName], tFilters[i]);
                if (dRows != null)
                {
                    resultDataSet.Merge(dRows);
                }
            }
            return resultDataSet;
        }

        public static DataSet GetNonFilteredEBMTDataSetG2()
        {
            DataSet resultDataSet = new DataSet();
            resultDataSet.EnforceConstraints = false;
            foreach (ExBindingSource ExBinSourceItem in binSourcesCollection)
            {
                if (ExBinSourceItem.isRecordFiltered == false)
                {
                    DataRow[] dRows = GetSelectedDataRows(ExBinSourceItem);
                    if (dRows != null)
                    {
                        resultDataSet.Merge(dRows);
                    }
                }
            }
            return resultDataSet;
        }

        public static DataRow[] GetSelectedDataRows(BindingSource myTableBindingSource, TableFilter tFilter)
        {
            DataRow[] dRows;
            if (myTableBindingSource.Count > 1)
            {
                if (tFilter.FilterText == "ALL")
                {
                    dRows = new DataRow[myTableBindingSource.Count];
                    int i = -1;
                    foreach (DataRowView dRowView in myTableBindingSource.List)
                    {
                        i = i + 1;
                        dRows[i] = dRowView.Row;
                    }
                    //return dRows;
                }
                else if (tFilter.FilterText == "FIRST")
                {
                    dRows = new DataRow[1];
                    DataRowView dRowView = (DataRowView) myTableBindingSource[0];
                    dRows[0] = dRowView.Row;
                }
                else if (tFilter.FilterText == "ONLY ONE")
                {
                    dRows = new DataRow[1];
                    DataRowView dRowView = (DataRowView) myTableBindingSource[0];
                    dRows[0] = dRowView.Row;
                }
                else if (tFilter.FilterText == "SECOND")
                {
                    if (myTableBindingSource.Count > 1)
                    {
                        dRows = new DataRow[1];
                        DataRowView dRowView = (DataRowView) myTableBindingSource[1];
                        dRows[0] = dRowView.Row;
                    }
                    else
                    {
                        dRows = new DataRow[1];
                        DataRowView dRowView = (DataRowView) myTableBindingSource[0];
                        dRows[0] = dRowView.Row;
                    }
                }
                else if (tFilter.FilterText == "THIRD")
                {
                    if (myTableBindingSource.Count > 2)
                    {
                        dRows = new DataRow[1];
                        DataRowView dRowView = (DataRowView) myTableBindingSource[2];
                        dRows[0] = dRowView.Row;
                    }
                    else
                    {
                        dRows = new DataRow[1];
                        DataRowView dRowView = (DataRowView) myTableBindingSource[0];
                        dRows[0] = dRowView.Row;
                    }
                }
                else if (tFilter.FilterText == "LAST")
                {
                    dRows = new DataRow[1];
                    DataRowView dRowView = (DataRowView) myTableBindingSource[myTableBindingSource.Count - 1];
                    dRows[0] = dRowView.Row;
                }
                else
                {
                    return null;
                }
                return dRows;
            }
            if (myTableBindingSource.Count == 1)
            {
                if (tFilter.FilterText == "[N]")
                {
                    dRows = new DataRow[1];
                    DataRowView dRowView = (DataRowView) myTableBindingSource[0];
                    dRows[0] = dRowView.Row;
                }
                else
                {
                    return null;
                }
                return dRows;
            }
            return null;
        }

        internal static DataRow[] GetSelectedDataRows(DataTable myTable, TableFilter tFilter)
        {
            if (myTable.Rows.Count > 0)
            {
                DataRow[] dRows;
                if (tFilter.FilterText == "ALL")
                {
                    dRows = new DataRow[myTable.Rows.Count];
                    int i = -1;
                    foreach (DataRow dRow in myTable.Rows)
                    {
                        i = i + 1;
                        dRows[i] = dRow;
                    }
                    return dRows;
                }
                if (tFilter.FilterText == "FIRST" || tFilter.FilterText == "[N]")
                {
                    dRows = new DataRow[1];
                    DataRow dRow = myTable.Rows[0];
                    dRows[0] = dRow;
                }
                else if (tFilter.FilterText == "ONLY ONE")
                {
                    dRows = new DataRow[1];
                    DataRow dRow = myTable.Rows[0];
                    dRows[0] = dRow;
                }
                else if (tFilter.FilterText == "SECOND")
                {
                    if (myTable.Rows.Count > 1)
                    {
                        dRows = new DataRow[1];
                        DataRow dRow = myTable.Rows[1];
                        dRows[0] = dRow;
                    }
                    else
                    {
                        dRows = new DataRow[1];
                        DataRow dRow = myTable.Rows[0];
                        dRows[0] = dRow;
                    }
                }
                else if (tFilter.FilterText == "THIRD")
                {
                    if (myTable.Rows.Count > 2)
                    {
                        dRows = new DataRow[1];
                        DataRow dRow = myTable.Rows[2];
                        dRows[0] = dRow;
                    }
                    else
                    {
                        dRows = new DataRow[1];
                        DataRow dRow = myTable.Rows[0];
                        dRows[0] = dRow;
                    }
                }
                else if (tFilter.FilterText == "LAST")
                {
                    dRows = new DataRow[1];
                    DataRow dRow = myTable.Rows[myTable.Rows.Count - 1];
                    dRows[0] = dRow;
                }
                else
                {
                    return null;
                }
                return dRows;
            }
            return null;
        }

        public static DataRow[] GetSelectedDataRows(BindingSource myTableBindingSource)
        {
            if (myTableBindingSource.Count > 0)
            {
                DataRow[] dRows = new DataRow[myTableBindingSource.Count];
                int i = -1;
                foreach (DataRowView dRowView in myTableBindingSource.List)
                {
                    i = i + 1;
                    dRows[i] = dRowView.Row;
                }
                return dRows;
            }
            return null;
        }

        public static DataTable GetEBMTFilteredDataTable(DataRow mappingCondition, DataSet ebmtFilteredDataSet)
        {
            DataTable myDataTable = null;
            if (ebmtFilteredDataSet.Tables.Contains(mappingCondition["EBMT ConTable ID"].ToString()))
            {
                myDataTable = ebmtFilteredDataSet.Tables[mappingCondition["EBMT ConTable ID"].ToString()];
            }
            else
            {
                if (GetExBindingSourceByTableName(mappingCondition["EBMT ConTable ID"].ToString()) == null)
                {
                    throw new Exception("Table name not found.");
                }
            }
            return myDataTable;
        }

        public static DataTable GetEBMTFilteredDataTable(string mapConditionTableName, DataSet ebmtFilteredDataSet)
        {
            DataTable myDataTable = null;
            if (ebmtFilteredDataSet.Tables.Contains(mapConditionTableName))
            {
                myDataTable = ebmtFilteredDataSet.Tables[mapConditionTableName];
            }
            return myDataTable;
        }

        public class TableFilter
        {
            internal string ftext;
            internal string rFilter;
            internal string tName;

            public string TableName
            {
                get { return tName; }
                set { tName = value; }
            }

            public string FilterText
            {
                get { return ftext; }
                set { ftext = value; }
            }

            public string RowsFilter
            {
                get { return rFilter; }
                set { rFilter = value; }
            }
        }

        #endregion

        #region Specific EBMT data functions.

        /// <summary>
        ///   Select the function name in the selected function row
        /// </summary>
        /// <param name="genericBindingSource"> BindingSource </param>
        /// <param name="functionRow"> RecordsSelectionFunctionsRow </param>
        /// <param name="repeatingSequenceNumber"> </param>
        /// <param name="dateOfTransplant"> </param>
        /// <returns> </returns>
        internal static DataRow[] GetFunctionResultingRows(BindingSource genericBindingSource, DataRow functionRow,
                                                           int repeatingSequenceNumber, DateTime dateOfTransplant)
        {
            RecordSelector recordSelector;

            switch (functionRow["EBMT RecFilter"].ToString())
            {
                case "ONLY ONE":
                    recordSelector = RecordSelector.ONE;
                    break;
                case "FIRST":
                    recordSelector = RecordSelector.FIRST;
                    break;
                case "SECOND":
                    recordSelector = RecordSelector.SECOND;
                    break;
                case "THIRD":
                    recordSelector = RecordSelector.THIRD;
                    break;
                case "LAST":
                    recordSelector = RecordSelector.LAST;
                    break;
                case "[N]":
                    if (repeatingSequenceNumber > 0)
                    {
                        if (repeatingSequenceNumber < 21 || repeatingSequenceNumber == 99 ||
                            repeatingSequenceNumber == 100)
                        {
                            recordSelector = (RecordSelector) repeatingSequenceNumber;
                        }
                        else
                        {
                            throw new Exception("The record selector doesn't allow this parameter: " +
                                                repeatingSequenceNumber);
                        }
                    }
                    else
                    {
                        recordSelector = RecordSelector.FIRST;
                    }
                    break;
                case "[N+1]":
                    int newRepSeqNumber = repeatingSequenceNumber + 1;
                    if (newRepSeqNumber > 0)
                    {
                        if (newRepSeqNumber < 21 || newRepSeqNumber == 99 || newRepSeqNumber == 100)
                        {
                            recordSelector = (RecordSelector) newRepSeqNumber;
                        }
                        else
                        {
                            throw new Exception("The record selector doesn't allow this parameter: " +
                                                repeatingSequenceNumber);
                        }
                    }
                    else
                    {
                        recordSelector = RecordSelector.SECOND;
                    }
                    break;
                case "ALL":
                    recordSelector = RecordSelector.ALL;
                    break;
                default:
                    recordSelector = RecordSelector.ALL;
                    break;
            }

            switch (functionRow["FunctionName"].ToString().Trim())
            {
                    //************************* TREATMENT FUNCTIONS *******************************************
                case "GetCurrentHSCTreatmentRecord":
                    return GetCurrentHSCTreatmentRecord(genericBindingSource, dateOfTransplant);
                case "GetNextHSCTreatmentRecord":
                    return GetNextHSCTreatmentRecord(genericBindingSource, dateOfTransplant);
                case "GetTreatmentRecordsAfterCurrHSCT":
                    return GetTreatmentRecordsAfterCurrHSCT(genericBindingSource, dateOfTransplant,
                                                            functionRow["FunctionRowFilter"].ToString());
                case "GetTreatmentRecordsFromCurrHSCTAndBeforeDueLimit":
                    return GetTreatmentRecordsFromCurrHSCTAndBeforeDueLimit(genericBindingSource, dateOfTransplant,
                                                                            recordSelector,
                                                                            functionRow["FunctionRowFilter"].ToString());
                case "GetTreatmentRecordsAfterCurrHSCTAndBeforeDueLimit":
                    return GetTreatmentRecordsAfterCurrHSCTAndBeforeDueLimit(genericBindingSource, dateOfTransplant,
                                                                             recordSelector,
                                                                             functionRow["FunctionRowFilter"].ToString());
                case "GetTreatmentRecordForPreviousHSCT":
                    return GetTreatmentRecordForPreviousHSCT(genericBindingSource, dateOfTransplant, recordSelector,
                                                             functionRow["FunctionRowFilter"].ToString());
                    //************************* ASSESMENT FUNCTIONS ********************************************
                case "GetAssesmentsAfterTransplant":
                    return GetAssesmentsAfterTransplant(genericBindingSource, dateOfTransplant, recordSelector,
                                                        functionRow["FunctionRowFilter"].ToString());
                case "GetCurrentHSCTAssesmentRecord":
                    return GetCurrentHSCTAssesmentRecord(genericBindingSource, dateOfTransplant);
                case "GetFirstAssesmentAfterCurrentTransplant":
                    return GetAssesmentsAfterTransplant(genericBindingSource, dateOfTransplant, RecordSelector.FIRST,
                                                        functionRow["FunctionRowFilter"].ToString());
                case "GetLastAssesmentAfterCurrentTransplant":
                    return GetAssesmentsAfterTransplant(genericBindingSource, dateOfTransplant, RecordSelector.LAST,
                                                        functionRow["FunctionRowFilter"].ToString());
                case "GetAssesmentRecordsFromCurrHSCTAndBeforeDueLimit":
                    return GetAssesmentRecordsFromCurrHSCTAndBeforeDueLimit(genericBindingSource, dateOfTransplant,
                                                                            recordSelector,
                                                                            functionRow["FunctionRowFilter"].ToString());
                case "GetAssesmentRecordsAfterCurrHSCTAndBeforeDueLimit":
                    return GetAssesmentRecordsAfterCurrHSCTAndBeforeDueLimit(genericBindingSource, dateOfTransplant,
                                                                             recordSelector,
                                                                             functionRow["FunctionRowFilter"].ToString());
                case "GetAssesmentRecordForNDLI":
                    return GetAssesmentRecordForNDLI(genericBindingSource, dateOfTransplant, recordSelector);
                case "GetAssesmentRecordsUntilCurrentHSCT":
                    return GetAssesmentRecordsUntilCurrentHSCT(genericBindingSource, dateOfTransplant, recordSelector,
                                                               functionRow["FunctionRowFilter"].ToString());
                case "GetAssesmentRecordsAfterCMLdiagDateAndBeforeCurrentHSCT":
                    //between date of diagnosis (CML) and current HSCT date
                case "GetAssesmentRecordsBetweenCMLdiagDateAndBeforeCurrentHSCT":
                    //RRA 06-09-2011
                    return GetAssesmentRecordsAfterCMLdiagDateAndBeforeCurrentHSCT(genericBindingSource,
                                                                                   dateOfTransplant, recordSelector,
                                                                                   functionRow["FunctionRowFilter"].
                                                                                       ToString());
                    //************************* DIAGNOSIS FUNCTIONS *********************************************
                case "GetAssesmentRecordForDiagOfCurrentHSCT":
                    //RRA 06-09-2011
                    return GetAssesmentRecordForDiagOfCurrentHSCT(genericBindingSource, dateOfTransplant, recordSelector,
                                                                  functionRow["FunctionRowFilter"].ToString());
                case "GetDiagnosisAfterCurrentTransplant":
                    return GetDiagnosisRecordsAfterADate(genericBindingSource, dateOfTransplant, recordSelector,
                                                         functionRow["FunctionRowFilter"].ToString());
                case "GetDiagnosisRecordsBeforeHSCT":
                    return GetDiagnosisRecordsBeforeHSCT(genericBindingSource, dateOfTransplant, recordSelector,
                                                         functionRow["FunctionRowFilter"].ToString());
                case "GetDiagnosisRecordsAfterCurrHSCTAndBeforeDueLimit":
                    return GetDiagnosisRecordsAfterCurrHSCTAndBeforeDueLimit(genericBindingSource, dateOfTransplant,
                                                                             recordSelector,
                                                                             functionRow["FunctionRowFilter"].ToString());
                    //**************************DRUGS FUNCTIONs***************************************************
                case "GetDrugRecordsFromCurrHSCTAndBeforeDueLimit":
                    return GetDrugRecordsFromCurrHSCTAndBeforeDueLimit(genericBindingSource, dateOfTransplant,
                                                                       recordSelector,
                                                                       functionRow["FunctionRowFilter"].ToString());
                case "GetDrugRecordsBeforeHSCT":
                    return GetDrugRecordsBeforeHSCT(genericBindingSource, dateOfTransplant, recordSelector,
                                                    functionRow["FunctionRowFilter"].ToString());
                case "GetDrugRecordsForCurrentHSCT":
                    // RRA 06-09-2011
                    return GetDrugRecordsForCurrentHSCT(genericBindingSource, dateOfTransplant, recordSelector,
                                                        functionRow["FunctionRowFilter"].ToString());
                case "GetDrugRecordsFromCurrentHSCTAndBeforeDateNextHSCTorDueDate":
                    //RRA 06-09-2011
                    return GetDrugRecordsFromCurrentHSCTAndBeforeDateNextHSCTorDueDate(genericBindingSource,
                                                                                       dateOfTransplant, recordSelector,
                                                                                       functionRow["FunctionRowFilter"].
                                                                                           ToString());
                case "GetDrugRecordsSinceCMLDiagDateAndBeforeCurrentHSCT":
                    //RRA 06-09-2011
                    return GetDrugRecordsSinceCMLDiagDateAndBeforeCurrentHSCT(genericBindingSource, dateOfTransplant,
                                                                              recordSelector,
                                                                              functionRow["FunctionRowFilter"].ToString());
                    //**************************DONOR FUNCTIONS****************************************************
                case "GetDonorRecordsForCurrentHSCT":
                    return GetDonorRecordsForCurrentHSCT(genericBindingSource, dateOfTransplant, recordSelector,
                                                         functionRow["FunctionRowFilter"].ToString());
                    //**************************OTHER FUNCTIONS****************************************************
                case "GetComplicationRecordsAfterCurrHSCTAndBeforeDueLimit":
                    return GetComplicationRecordsAfterCurrHSCTAndBeforeDueLimit(genericBindingSource, dateOfTransplant,
                                                                                recordSelector,
                                                                                functionRow["FunctionRowFilter"].
                                                                                    ToString());
                case "GetCytogeneticsAndMolecularRecordBeforeCurrentHSCT":
                    //RRA 06-09-2011
                    return GetCytogeneticsAndMolecularRecordBeforeCurrentHSCT(genericBindingSource, dateOfTransplant,
                                                                              recordSelector,
                                                                              functionRow["FunctionRowFilter"].ToString());
                case "GetMolecularRecordsBeforeCurrentHSCT":
                    //RRA 06-09-2011
                    return GetMolecularRecordsBeforeCurrentHSCT(genericBindingSource, dateOfTransplant, recordSelector,
                                                                functionRow["FunctionRowFilter"].ToString());
                case "GetClinicalProblemRecordForDiagOfCurrentHSCT":
                    return GetClinicalProblemRecordForDiagOfCurrentHSCT(genericBindingSource, dateOfTransplant,
                                                                        recordSelector,
                                                                        functionRow["FunctionRowFilter"].ToString());
                case "GetCirculatingAntibodyRecordForDiagOfCurrentHSCT":
                    return GetCirculatingAntibodyRecordForDiagOfCurrentHSCT(genericBindingSource, dateOfTransplant,
                                                                            recordSelector);
                case "StillToImplement":
                    return null;
                default:
                    throw new Exception("The function name provided from the RecordsSelection table is not correct." +
                                        "Please verify the table");
            }
        }

        internal static DateTime GetDateOfDueLimit(BindingSource trBindingSource, DateTime transplantDate)
        {
            DateTime dateOfFormDueState = transplantDate.AddDays(100);
            trBindingSource.Filter = "IDAABC>#" +
                                     transplantDate.ToString(
                                         CultureInfo.CreateSpecificCulture("en-US")) +
                                     "# AND IDAABC<#" +
                                     dateOfFormDueState.ToString(
                                         CultureInfo.CreateSpecificCulture("en-US")) +
                                     "# AND _BC_EVD='7'";
            if (trBindingSource.Count > 0)
            {
                DataRowView dRowView = (DataRowView) trBindingSource[0];
                dateOfFormDueState = (DateTime) dRowView["IDAABC"];
                return dateOfFormDueState;
            }
            return dateOfFormDueState;
        }

        internal static DateTime GetDateOfPreviousHSCT(BindingSource trBindingSource, DateTime transplantDate)
        {
            DateTime DateOfPreviousHSCT = DateTime.Today;
            trBindingSource.Filter = "IDAABC<#" +
                                     transplantDate.ToString(
                                         CultureInfo.CreateSpecificCulture("en-US")) + "#";
            if (trBindingSource.Count > 0)
            {
                DataRowView dRowView = (DataRowView) trBindingSource[trBindingSource.Count - 1];
                DateOfPreviousHSCT = (DateTime) dRowView["IDAABC"];
                return DateOfPreviousHSCT;
            }
            return DateOfPreviousHSCT; //there isn't any previous HSCT
        }

        internal static DateTime GetNextHSCTDate(BindingSource trBindingSource, DateTime transplantDate)
        {
            DateTime DateOfNextHSCT = DateTime.Today;
            trBindingSource.Filter = "IDAABC>#" +
                                     transplantDate.ToString(
                                         CultureInfo.CreateSpecificCulture("en-US")) + "#";
            if (trBindingSource.Count > 0)
            {
                DataRowView dRowView = (DataRowView) trBindingSource[trBindingSource.Count - 1];
                DateOfNextHSCT = (DateTime) dRowView["IDAABC"];
                return DateOfNextHSCT;
            }
            return DateOfNextHSCT; //Any Treatment (HSCT) occured after the Date of transplant
        }

        //RRA 05-09-2011
        internal static DateTime GetNextHSCTDate_or_DueDate(BindingSource trBindingSource, DateTime transplantDate)
        {
            return GetNextHSCTDate(trBindingSource, transplantDate) == DateTime.Today ? GetDateOfDueLimit(GetExBindingSourceByTableName("B2"), transplantDate) : GetNextHSCTDate(trBindingSource, transplantDate);
        }

        //RRA 05-09-2011
        internal static DateTime GetDateOfDiagnosis(BindingSource trBindingSource, DateTime transplantDate)
        {
            DateTime DateOfDiag = DateTime.Today;
            trBindingSource.Filter = "IDAABB=#" +
                                     transplantDate.ToString(
                                         CultureInfo.CreateSpecificCulture("en-US")) + "#";
            if (trBindingSource.Count > 0)
            {
                DataRowView dRowView = (DataRowView) trBindingSource[trBindingSource.Count - 1];
                DateOfDiag = (DateTime) dRowView["IDAABB"];
                return DateOfDiag;
            }
            return DateOfDiag; //any diagnosis occured at this date
        }

        #region Records selection functions

        #region Transplants related functions

        internal static DataRow[] GetCurrentHSCTreatmentRecord(BindingSource tBindingSource, DateTime transplantDate)
        {
            return GetHSCTreatmentRecord(tBindingSource, transplantDate);
        }

        internal static DataRow[] GetNextHSCTreatmentRecord(BindingSource tBindingSource, DateTime transplantDate)
        {
            return GetHSCTreatmentRecordsAfterADate(tBindingSource, transplantDate, RecordSelector.FIRST);
        }

        internal static DataRow[] GetHSCTreatmentRecord(BindingSource tBindingSource, DateTime transplantDate)
        {
            tBindingSource.Filter = "IDAABC=#" +
                                    transplantDate.ToString(
                                        CultureInfo.CreateSpecificCulture("en-US")) +
                                    "# AND _BC_EVD='7'";
            if (tBindingSource.Count > 0)
            {
                DataRow[] dRows = new DataRow[1];
                DataRowView dRowView = (DataRowView) tBindingSource[0];
                dRows[0] = dRowView.Row;
                return dRows;
            }
            return null;
        }

        internal static DataRow[] GetHSCTreatmentRecordsAfterADate(BindingSource trBindingSource, DateTime aDate,
                                                                   RecordSelector recordSelector)
        {
            trBindingSource.Filter = "IDAABC>#" +
                                     aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                     "# AND _BC_EVD='7'";
            return trBindingSource.Count > 0 ? ApplyRowsSelector(trBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetHSCTransplantRecordsBeforeADate(BindingSource trBindingSource, DateTime aDate,
                                                                     RecordSelector recordSelector)
        {
            trBindingSource.Filter = "IDAABC<#" +
                                     aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                     "# AND _BC_EVD='7'";
            return trBindingSource.Count > 0 ? ApplyRowsSelector(trBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetHSCTransplantRecordsAfterDate1AndBeforeDate2(BindingSource trBindingSource,
                                                                                  DateTime aDate1, DateTime aDate2,
                                                                                  RecordSelector recordSelector)
        {
            trBindingSource.Filter = "IDAABC>#" +
                                     aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                     "# AND IDAABC<#"
                                     + aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                     "# AND _BC_EVD='7'";
            return trBindingSource.Count > 0 ? ApplyRowsSelector(trBindingSource, recordSelector) : null;
        }

        #endregion

        #region Treatments related functions

        internal static DataRow[] GetTreatmentRecordsFromCurrHSCTAndBeforeDueLimit(BindingSource trBindingSource,
                                                                                   DateTime transplantDate,
                                                                                   RecordSelector recordSelector,
                                                                                   string functionRowFilter)
        {
            DateTime dOfDueLimit = GetDateOfDueLimit(trBindingSource, transplantDate);
            return GetTreatmentRecordsFromDate1AndBeforeDate2(trBindingSource, transplantDate, dOfDueLimit,
                                                              recordSelector, functionRowFilter);
        }

        internal static DataRow[] GetTreatmentRecordsAfterCurrHSCTAndBeforeDueLimit(BindingSource trBindingSource,
                                                                                    DateTime transplantDate,
                                                                                    RecordSelector recordSelector,
                                                                                    string functionRowFilter)
        {
            DateTime dOfDueLimit = GetDateOfDueLimit(trBindingSource, transplantDate);
            return GetTreatmentRecordsAfterDate1AndBeforeDate2(trBindingSource, transplantDate, dOfDueLimit,
                                                               recordSelector, functionRowFilter);
        }

        internal static DataRow[] GetTreatmentRecordsAfterCurrHSCT(BindingSource trBindingSource,
                                                                   DateTime transplantDate, string functionRowFilter)
        {
            return GetTreatmentRecordsAfterADate(trBindingSource, transplantDate, RecordSelector.ALL, functionRowFilter);
        }

        internal static DataRow[] GetTreatmentRecordsAfterADate(BindingSource trBindingSource, DateTime aDate,
                                                                RecordSelector recordSelector, string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                trBindingSource.Filter = "IDAABC>#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                trBindingSource.Filter = "IDAABC>#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }

            return trBindingSource.Count > 0 ? ApplyRowsSelector(trBindingSource, recordSelector) : null;
        }

        //RRA 2400
        internal static DataRow[] GetTreatmentRecordForCurrentHSCT(BindingSource trBindingSource,
                                                                   DateTime transplantDate,
                                                                   RecordSelector recordSelector,
                                                                   string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                trBindingSource.Filter = "IDAABC=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "# AND " +
                                         functionRowFilter;
            }
            else
            {
                trBindingSource.Filter = "IDAABC=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "#";
            }
            return trBindingSource.Count > 0 ? ApplyRowsSelector(trBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetTreatmentRecordForPreviousHSCT(BindingSource trBindingSource,
                                                                    DateTime transplantDate,
                                                                    RecordSelector recordSelector,
                                                                    string functionRowFilter)
        {
            DateTime PreviousHSCTDate = GetDateOfPreviousHSCT(trBindingSource, transplantDate);
            return GetTreatmentRecordForPreviousHSCTDate(trBindingSource, PreviousHSCTDate, recordSelector,
                                                         functionRowFilter);
        }

        internal static DataRow[] GetTreatmentRecordForPreviousHSCTDate(BindingSource trBindingSource,
                                                                        DateTime PreviousHSCTDate,
                                                                        RecordSelector recordSelector,
                                                                        string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                trBindingSource.Filter = "IDAABC=#" +
                                         PreviousHSCTDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "# AND " +
                                         functionRowFilter;
            }
            else
            {
                trBindingSource.Filter = "IDAABC=#" +
                                         PreviousHSCTDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "#";
            }
            return trBindingSource.Count > 0 ? ApplyRowsSelector(trBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetTransplantRecordsBeforeADate(BindingSource trBindingSource, DateTime aDate,
                                                                  RecordSelector recordSelector,
                                                                  string functionRowFilter)
        {
            if (functionRowFilter != null)
            {
                trBindingSource.Filter = "IDAABC<#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                trBindingSource.Filter = "IDAABC<#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }
            return trBindingSource.Count > 0 ? ApplyRowsSelector(trBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetTreatmentRecordsAfterDate1AndBeforeDate2(BindingSource trBindingSource,
                                                                              DateTime aDate1, DateTime aDate2,
                                                                              RecordSelector recordSelector,
                                                                              string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                trBindingSource.Filter = "IDAABC>#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US"))
                                         + "# AND IDAABC<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                trBindingSource.Filter = "IDAABC>#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US"))
                                         + "# AND IDAABC<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }
            return trBindingSource.Count > 0 ? ApplyRowsSelector(trBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetTreatmentRecordsFromDate1AndBeforeDate2(BindingSource trBindingSource,
                                                                             DateTime aDate1, DateTime aDate2,
                                                                             RecordSelector recordSelector,
                                                                             string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                trBindingSource.Filter = "IDAABC>=#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US"))
                                         + "# AND IDAABC<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                trBindingSource.Filter = "IDAABC>=#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US"))
                                         + "# AND IDAABC<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }

            return trBindingSource.Count > 0 ? ApplyRowsSelector(trBindingSource, recordSelector) : null;
        }

        #endregion

        #region Assesments related functions

        internal static DataRow[] GetCurrentHSCTAssesmentRecord(BindingSource asBindingSource, DateTime dateOfTransplant)
        {
            return GetAssesmentRecord(asBindingSource, dateOfTransplant);
        }

        internal static DataRow[] GetAssesmentRecordsFromCurrHSCTAndBeforeDueLimit(BindingSource asBindingSource,
                                                                                   DateTime transplantDate,
                                                                                   RecordSelector recordSelector,
                                                                                   string functionRowFilter)
        {
            DateTime dOfDueLimit = GetDateOfDueLimit(GetExBindingSourceByTableName("B2"), transplantDate);
            return GetAssesmentRecordsFromDate1AndBeforeDate2(asBindingSource, transplantDate, dOfDueLimit,
                                                              recordSelector, functionRowFilter);
        }

        internal static DataRow[] GetAssesmentRecordsAfterCurrHSCTAndBeforeDueLimit(BindingSource asBindingSource,
                                                                                    DateTime transplantDate,
                                                                                    RecordSelector recordSelector,
                                                                                    string functionRowFilter)
        {
            DateTime dOfDueLimit = GetDateOfDueLimit(GetExBindingSourceByTableName("B2"), transplantDate);
            return GetAssesmentRecordsAfterDate1AndBeforeDate2(asBindingSource, transplantDate, dOfDueLimit,
                                                               recordSelector, functionRowFilter);
        }

        internal static DataRow[] GetAssesmentRecord(BindingSource asBindingSource, DateTime aDate)
        {
            asBindingSource.Filter = "IDAABE=#" +
                                     aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                     "#";
            if (asBindingSource.Count > 0)
            {
                DataRow[] dRows = new DataRow[1];
                DataRowView dRowView = (DataRowView) asBindingSource[0];
                dRows[0] = dRowView.Row;
                return dRows;
            }

            return null;
        }

        //RRA 2400
        /// <summary>
        ///   may be called also GetAssesmentRecordsBeforeCurrentHSCT, but this includes the date whereas 'before' exlude it
        /// </summary>
        /// <returns> </returns>
        internal static DataRow[] GetAssesmentRecordsUntilCurrentHSCT(BindingSource assesmentsBindingSource,
                                                                      DateTime dateOfTransplant,
                                                                      RecordSelector recordSelector,
                                                                      string functionRowFilter)
        {
            if (assesmentsBindingSource != null)
            {
                return GetAssesmentRecordsUntilADate(assesmentsBindingSource, dateOfTransplant, recordSelector,
                                                     functionRowFilter);
            }
            return null;
        }

        internal static DataRow[] GetAssesmentsAfterTransplant(BindingSource assesmentsBindingSource,
                                                               DateTime dateOfTransplant, RecordSelector recordSelector,
                                                               string functionRowFilter)
        {
            if (assesmentsBindingSource != null)
            {
                return GetAssesmentRecordsAfterADate(assesmentsBindingSource, dateOfTransplant, recordSelector,
                                                     functionRowFilter);
            }
            return null;
        }

        //RRA 2400
        internal static DataRow[] GetAssesmentRecordsUntilADate(BindingSource asBindingSource, DateTime aDate,
                                                                RecordSelector recordSelector, string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                asBindingSource.Filter = "IDAABE<=#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                asBindingSource.Filter = "IDAABE<=#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }
            return asBindingSource.Count > 0 ? ApplyRowsSelector(asBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetAssesmentRecordsAfterADate(BindingSource asBindingSource, DateTime aDate,
                                                                RecordSelector recordSelector, string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                asBindingSource.Filter = "IDAABE>#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                asBindingSource.Filter = "IDAABE>#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }
            return asBindingSource.Count > 0 ? ApplyRowsSelector(asBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetAssesmentRecordsAfterDate1AndBeforeDate2(BindingSource asBindingSource,
                                                                              DateTime aDate1, DateTime aDate2,
                                                                              RecordSelector recordSelector,
                                                                              string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                asBindingSource.Filter = "IDAABE>#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US"))
                                         + "# AND IDAABE<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                asBindingSource.Filter = "IDAABE>#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US"))
                                         + "# AND IDAABE<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }
            return asBindingSource.Count > 0 ? ApplyRowsSelector(asBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetAssesmentRecordsFromDate1AndBeforeDate2(BindingSource asBindingSource,
                                                                             DateTime aDate1, DateTime aDate2,
                                                                             RecordSelector recordSelector,
                                                                             string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                asBindingSource.Filter = "IDAABE>=#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US"))
                                         + "# AND IDAABE<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                asBindingSource.Filter = "IDAABE>=#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US"))
                                         + "# AND IDAABE<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }
            return asBindingSource.Count > 0 ? ApplyRowsSelector(asBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetAssesmentRecordForNDLI(BindingSource asBindingSource, DateTime dateOfTransplant,
                                                            RecordSelector recordSelector)
        {
            DataRow[] dliTransplant =
                GetTreatmentRecordsAfterCurrHSCTAndBeforeDueLimit(GetExBindingSourceByTableName("B2"), dateOfTransplant,
                                                                  recordSelector, "VADLYMPH='2'");
            if (dliTransplant != null)
            {
                DateTime dliTransplantDate = (DateTime) dliTransplant[0]["IDAABC"];
                return GetAssesmentRecord(asBindingSource, dliTransplantDate);
            }
            return null;
        }

        //RRA 2400
        internal static DataRow[] GetAssesmentRecordsAfterCMLdiagDateAndBeforeCurrentHSCT(BindingSource asBindingSource,
                                                                                          DateTime dateOfTransplant,
                                                                                          RecordSelector recordSelector,
                                                                                          string functionRowFilter)
        {
            //DateTime CMLdiagDate = GetDateOfDiagnosis(GetExBindingSourceByTableName("B1"), dateOfTransplant);
            DateTime CMLdiagDate = GetDateOfDiagnosis(GetExBindingSourceByTableName("B1"), dateOfTransplant);
            if (functionRowFilter != "")
            {
                asBindingSource.Filter = "IDAABE>#" +
                                         CMLdiagDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND IDAABE<#" +
                                         dateOfTransplant.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "# AND " +
                                         functionRowFilter;
            }
            else
            {
                asBindingSource.Filter = "IDAABE>#" +
                                         CMLdiagDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND IDAABE<#" +
                                         dateOfTransplant.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "#";
            }
            return asBindingSource.Count > 0 ? ApplyRowsSelector(asBindingSource, recordSelector) : null;
        }

        #endregion

        #region Diagnosis related functions

        internal static DataRow[] GetAssesmentRecordForDiagOfCurrentHSCT(BindingSource diBindingSource,
                                                                         DateTime CurrentHSCTDate,
                                                                         RecordSelector recordSelector,
                                                                         string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                diBindingSource.Filter = "IDAABE=#" +
                                         CurrentHSCTDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "# AND " +
                                         functionRowFilter;
            }
            else
            {
                diBindingSource.Filter = "IDAABE=#" +
                                         CurrentHSCTDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "#";
            }
            return diBindingSource.Count > 0 ? ApplyRowsSelector(diBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetDiagnosisRecordsAfterADate(BindingSource diBindingSource, DateTime aDate,
                                                                RecordSelector recordSelector, string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                diBindingSource.Filter = "IDAABB>#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                diBindingSource.Filter = "IDAABB>#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }
            return diBindingSource.Count > 0 ? ApplyRowsSelector(diBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetDiagnosisRecordsBeforeADate(BindingSource diBindingSource, DateTime aDate,
                                                                 RecordSelector recordSelector, string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                diBindingSource.Filter = "IDAABB<#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                diBindingSource.Filter = "IDAABB<#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }
            return diBindingSource.Count > 0 ? ApplyRowsSelector(diBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetDiagnosisRecordsBeforeHSCT(BindingSource diBindingSource, DateTime transplantDate,
                                                                RecordSelector recordSelector, string functionRowFilter)
        {
            return GetDiagnosisRecordsBeforeADate(diBindingSource, transplantDate, recordSelector, functionRowFilter);
        }

        internal static DataRow[] GetMainDiagnosisRecordsAfterADate(BindingSource diBindingSource, DateTime aDate,
                                                                    RecordSelector recordSelector,
                                                                    string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                diBindingSource.Filter = "IDAABB>#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND _BB_EVD='1' AND " + functionRowFilter;
            }
            else
            {
                diBindingSource.Filter = "IDAABB>#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND _BB_EVD='1'";
            }
            return diBindingSource.Count > 0 ? ApplyRowsSelector(diBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetMainDiagnosisRecordsBeforeADate(BindingSource diBindingSource, DateTime aDate,
                                                                     RecordSelector recordSelector,
                                                                     string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                diBindingSource.Filter = "IDAABB<#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND _BB_EVD='1' AND " + functionRowFilter;
            }
            else
            {
                diBindingSource.Filter = "IDAABB<#" +
                                         aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND _BB_EVD='1'";
            }
            return diBindingSource.Count > 0 ? ApplyRowsSelector(diBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetDiagnosisRecordsAfterCurrHSCTAndBeforeDueLimit(BindingSource diBindingSource,
                                                                                    DateTime transplantDate,
                                                                                    RecordSelector recordSelector,
                                                                                    string functionRowFilter)
        {
            DateTime dOfDueLimit = GetDateOfDueLimit(GetExBindingSourceByTableName("B2"), transplantDate);
            return GetDiagnosisRecordsAfterDate1AndBeforeDate2(diBindingSource, transplantDate, dOfDueLimit,
                                                               recordSelector, functionRowFilter);
        }

        internal static DataRow[] GetDiagnosisRecordsAfterDate1AndBeforeDate2(BindingSource diBindingSource,
                                                                              DateTime aDate1, DateTime aDate2,
                                                                              RecordSelector recordSelector,
                                                                              string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                diBindingSource.Filter = "IDAABB>#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND IDAABB<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                diBindingSource.Filter = "IDAABB>#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND IDAABB<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }
            return diBindingSource.Count > 0 ? ApplyRowsSelector(diBindingSource, recordSelector) : null;
        }


        internal static DataRow[] ApplyRowsSelector(BindingSource gBindingSource, RecordSelector recordSelector)
        {
            DataRow[] dRows = null;
            if (recordSelector == RecordSelector.ALL)
            {
                dRows = new DataRow[gBindingSource.Count];
                int i = -1;
                foreach (DataRowView dRowView in gBindingSource.List)
                {
                    i = i + 1;
                    dRows[i] = dRowView.Row;
                }
            }
            else if (recordSelector == RecordSelector.LAST)
            {
                dRows = new DataRow[1];
                DataRowView dRowView = (DataRowView) gBindingSource[gBindingSource.Count - 1];
                dRows[0] = dRowView.Row;
            }
            else if ((int) recordSelector <= gBindingSource.Count)
            {
                dRows = new DataRow[1];
                DataRowView dRowView = (DataRowView) gBindingSource[(int) recordSelector - 1];
                dRows[0] = dRowView.Row;
            }
            return dRows;
        }

        #endregion

        #region Donor related functions

        internal static DataRow[] GetDonorRecordsForCurrentHSCT(BindingSource DonorBindingSource,
                                                                DateTime dateOfTransplant, RecordSelector recordSelector,
                                                                string functionRowFilter)
        {
            DonorBindingSource.Filter = "IDAABC=#" +
                                        dateOfTransplant.ToString(
                                            CultureInfo.CreateSpecificCulture("en-US")) + "#";
            return DonorBindingSource.Count > 0 ? ApplyRowsSelector(DonorBindingSource, recordSelector) : null;
        }

        #endregion

        #region Drugs related functions

        internal static DataRow[] GetDrugRecordsFromCurrHSCTAndBeforeDueLimit(BindingSource drBindingSource,
                                                                              DateTime transplantDate,
                                                                              RecordSelector recordSelector,
                                                                              string functionRowFilter)
        {
            DateTime dOfDueLimit = GetDateOfDueLimit(GetExBindingSourceByTableName("B2"), transplantDate);
            return GetDrugRecordsFromDate1AndBeforeDate2(drBindingSource, transplantDate, dOfDueLimit, recordSelector,
                                                         functionRowFilter);
        }

        //RRA 
        internal static DataRow[] GetDrugRecordsBeforeHSCT(BindingSource drBindingSource, DateTime transplantDate,
                                                           RecordSelector recordSelector, string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                drBindingSource.Filter = "IDAABC<=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "# AND " +
                                         functionRowFilter;
            }
            else
            {
                drBindingSource.Filter = "IDAABC<=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "#";
            }
            return drBindingSource.Count > 0 ? ApplyRowsSelector(drBindingSource, recordSelector) : null;
        }

        //RRA
        internal static DataRow[] GetDrugRecordsForCurrentHSCT(BindingSource drBindingSource, DateTime transplantDate,
                                                               RecordSelector recordSelector, string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                drBindingSource.Filter = "IDAABC=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "# AND " +
                                         functionRowFilter;
            }
            else
            {
                drBindingSource.Filter = "IDAABC=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "#";
            }
            return drBindingSource.Count > 0 ? ApplyRowsSelector(drBindingSource, recordSelector) : null;
        }

        //RRA
        internal static DataRow[] GetDrugRecordsFromCurrentHSCTAndBeforeDateNextHSCTorDueDate(
            BindingSource drBindingSource, DateTime CurrentHSCTDate, RecordSelector recordSelector,
            string functionRowFilter)
        {
            DateTime NextHSCTorDueDate = GetNextHSCTDate_or_DueDate(drBindingSource, CurrentHSCTDate);
            return GetDrugRecordsFromDate1AndBeforeDate2(drBindingSource, CurrentHSCTDate, NextHSCTorDueDate,
                                                         recordSelector, functionRowFilter);
        }

        //RRA
        internal static DataRow[] GetDrugRecordsSinceCMLDiagDateAndBeforeCurrentHSCT(BindingSource drBindingSource,
                                                                                     DateTime CurrentHSCTDate,
                                                                                     RecordSelector recordSelector,
                                                                                     string functionRowFilter)
        {
            DateTime CMLdiagDate = GetDateOfDiagnosis(GetExBindingSourceByTableName("B1"), CurrentHSCTDate);
            return GetDrugRecordsFromDate1AndBeforeDate2(drBindingSource, CurrentHSCTDate, CMLdiagDate, recordSelector,
                                                         functionRowFilter);
        }

        internal static DataRow[] GetDrugRecordsFromDate1AndBeforeDate2(BindingSource drBindingSource, DateTime aDate1,
                                                                        DateTime aDate2, RecordSelector recordSelector,
                                                                        string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                drBindingSource.Filter = "IDAABC>=#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND IDAABC<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND " + functionRowFilter;
            }
            else
            {
                drBindingSource.Filter = "IDAABC>=#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND IDAABC<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }

            return drBindingSource.Count > 0 ? ApplyRowsSelector(drBindingSource, recordSelector) : null;
        }

        #endregion

        #region Clinical Problem Record functions

        /// <summary>
        ///   all clinical problem record for diagnosis of the current HSCT
        /// </summary>
        /// <param name="asBindingSource"> </param>
        /// <param name="transplantDate"> </param>
        /// <param name="recordSelector"> </param>
        /// <param name="functionRowFilter"> </param>
        /// <returns> </returns>
        internal static DataRow[] GetClinicalProblemRecordForDiagOfCurrentHSCT(BindingSource asBindingSource,
                                                                               DateTime transplantDate,
                                                                               RecordSelector recordSelector,
                                                                               string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                asBindingSource.Filter = "IDAABE=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "# AND " +
                                         functionRowFilter;
            }
            else
            {
                asBindingSource.Filter = "IDAABE=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "#";
            }
            return asBindingSource.Count > 0 ? ApplyRowsSelector(asBindingSource, recordSelector) : null;
        }

        internal static DataRow[] GetCirculatingAntibodyRecordForDiagOfCurrentHSCT(BindingSource asBindingSource,
                                                                                   DateTime aDate,
                                                                                   RecordSelector recordSelector)
        {
            asBindingSource.Filter = "IDAABE=#" +
                                     aDate.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                     "#";
            return asBindingSource.Count > 0 ? ApplyRowsSelector(asBindingSource, recordSelector) : null;
        }

        #endregion

        #region Other functions

        //RRA 06-09-2011       
        internal static DataRow[] GetMolecularRecordsBeforeCurrentHSCT(BindingSource drBindingSource,
                                                                       DateTime transplantDate,
                                                                       RecordSelector recordSelector,
                                                                       string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                drBindingSource.Filter = "IDAABE<=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "# AND " +
                                         functionRowFilter;
            }
            else
            {
                drBindingSource.Filter = "IDAABE<=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "#";
            }
            return drBindingSource.Count > 0 ? ApplyRowsSelector(drBindingSource, recordSelector) : null;
        }

        //RRA 06-09-2011
        /// <summary>
        ///   What we want is a selection from the Cytogenetic table (CC) but some conditions are using Molecular table
        /// </summary>
        /// <returns> </returns>
        internal static DataRow[] GetCytogeneticsAndMolecularRecordBeforeCurrentHSCT(BindingSource drBindingSource,
                                                                                     DateTime transplantDate,
                                                                                     RecordSelector recordSelector,
                                                                                     string functionRowFilter)
        {
            if (functionRowFilter != "")
            {
                drBindingSource.Filter = "IDAABE<=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "# AND " +
                                         functionRowFilter;
            }
            else
            {
                drBindingSource.Filter = "IDAABE<=#" +
                                         transplantDate.ToString(
                                             CultureInfo.CreateSpecificCulture("en-US")) + "#";
            }
            return drBindingSource.Count > 0 ? ApplyRowsSelector(drBindingSource, recordSelector) : null;
        }

        /// <summary>
        ///   Return complications records between the period after current HSCT and before next or due time.
        /// </summary>
        /// <param name="drBindingSource"> The bindingsource object related to the complications table. </param>
        /// <param name="transplantDate"> The current HSCT date of transplant. </param>
        /// <param name="recordSelector"> </param>
        /// <param name="functionRowFilter"> Another filter to add to the selection, this needs to be written in the SQL format. </param>
        /// <returns> </returns>
        internal static DataRow[] GetComplicationRecordsAfterCurrHSCTAndBeforeDueLimit(BindingSource drBindingSource,
                                                                                       DateTime transplantDate,
                                                                                       RecordSelector recordSelector,
                                                                                       string functionRowFilter)
        {
            DateTime dOfDueLimit = GetDateOfDueLimit(GetExBindingSourceByTableName("B2"), transplantDate);
            return GetComplicationRecordsAfterDate1AndBeforeDate2(drBindingSource, transplantDate, dOfDueLimit,
                                                                  recordSelector, functionRowFilter);
        }

        internal static DataRow[] GetComplicationRecordsAfterDate1AndBeforeDate2(BindingSource drBindingSource,
                                                                                 DateTime aDate1, DateTime aDate2,
                                                                                 RecordSelector recordSelector,
                                                                                 string functionRowFilter)
        {
            string sD1 = aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US"));
            string sD2 = aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US"));
            if (functionRowFilter != "")
            {
                drBindingSource.Filter = "IDAABE>#" + sD1 + "# AND IDAABE<#" + sD2 + "# AND " + functionRowFilter;
            }
            else
            {
                drBindingSource.Filter = "IDAABE>#" +
                                         aDate1.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "# AND IDAABE<#" +
                                         aDate2.ToString(CultureInfo.CreateSpecificCulture("en-US")) +
                                         "#";
            }

            return drBindingSource.Count > 0 ? ApplyRowsSelector(drBindingSource, recordSelector) : null;
        }


        public static String GetEBMTVariableValueDescription(String variableName, int valueGroupCode, int valueCode)
        {
            ExBindingSource bsEBMTCodes = GetExBindingSourceByTableName("TDIC_LAB");
            bsEBMTCodes.Filter = "LBISET='" + valueGroupCode + "' AND LBIVAL='" + valueCode + "'";
            if (bsEBMTCodes.Count == 1)
            {
                DataRowView drView = (DataRowView) bsEBMTCodes[0];
                return drView["LBISTR"].ToString();
            }
            return valueCode.ToString();
        }

        #endregion

        #endregion

        #region Mapping Exceptions Functions

        //RRA 2900
        public static TranslationAnswer Get_CTRB_DTH_RSN_TP_A_Value(DateTime dateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Record Selection is : last assesment where (VPATSTAT=1 or VPATSTAT=3)
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            const string assesmentRowfilter = "(GRAVHOSD='1' or GRAVHOSD=null) AND (AGVHGRMX<7)";

            DataRow[] assesmentRecords = GetAssesmentsAfterTransplant(assesmentBs, dateOfTransplant, RecordSelector.ALL,
                                                                      assesmentRowfilter);
            if (assesmentRecords != null)
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_CTRB_DTH_RSN_TP_B_Value(DateTime dateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Record Selection is : last assesment where (VPATSTAT=1 or VPATSTAT=3)
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            const string assesmentRowfilter = "(GRAVHOSD>1 and GRAVHOSD<99) AND AGVHGRMX='7'";

            DataRow[] assesmentRecords = GetAssesmentsAfterTransplant(assesmentBs, dateOfTransplant, RecordSelector.LAST,
                                                                      assesmentRowfilter);
            if (assesmentRecords != null)
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_N_MN_LMM_DIS_DIA_IND_Value(DateTime dateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get all diagnosis and complication records after current HSCT and before (next HSCT or form due date)
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            ExBindingSource complicationsBs = GetExBindingSourceByTableName("CA_");
            //Test if ((DISMCLFD='3' AND VREALCLS<'200' AND VREALCLS<>'60' AND VREALCLS<>'140') OR (DISMCLFD='3' AND VREALCLS='300')) 
            const string diagnosisRowFilter = "((DISMCLFD='3' AND VREALCLS<'200' AND VREALCLS<>'60' AND VREALCLS<>'140') OR (DISMCLFD='3' AND VREALCLS='300'))";
            //or Test if IDAABECA='103'
            DataRow[] diagRecords = GetDiagnosisRecordsAfterCurrHSCTAndBeforeDueLimit(diagnosisBs, dateOfTransplant,
                                                                                      RecordSelector.ALL,
                                                                                      diagnosisRowFilter);
            DataRow[] compRecords = GetComplicationRecordsAfterCurrHSCTAndBeforeDueLimit(complicationsBs,
                                                                                         dateOfTransplant,
                                                                                         RecordSelector.ALL,
                                                                                         "IDAABECA='103'");

            if (diagRecords != null)
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = "Yes";
            }
            if (compRecords != null)
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = "Yes";
            }

            return myAnswer;
        }

        public static TranslationAnswer Get_NMN_LMM_DIS_DX_DT_Value(DateTime dateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get all diagnosis and complication records after current HSCT and before (next HSCT or form due date)
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            ExBindingSource complicationsBs = GetExBindingSourceByTableName("CA_");
            //Test if ((DISMCLFD='3' AND VREALCLS<'200' AND VREALCLS<>'60' AND VREALCLS<>'140') OR (DISMCLFD='3' AND VREALCLS='300')) 
            const string diagnosisRowFilter = "((DISMCLFD='3' AND VREALCLS<'200' AND VREALCLS<>'60' AND VREALCLS<>'140') OR (DISMCLFD='3' AND VREALCLS='300'))";
            //or Test if IDAABECA='103'
            DataRow[] diagRecords = GetDiagnosisRecordsAfterCurrHSCTAndBeforeDueLimit(diagnosisBs, dateOfTransplant,
                                                                                      RecordSelector.ALL,
                                                                                      diagnosisRowFilter);
            DataRow[] compRecords = GetComplicationRecordsAfterCurrHSCTAndBeforeDueLimit(complicationsBs,
                                                                                         dateOfTransplant,
                                                                                         RecordSelector.ALL,
                                                                                         "IDAABECA='103'");

            //B1.IDAABB WHEN diagnosisRowFilter is TRUE 
            //OR CA_.DBEGCOM WHEN IDAABECA=103
            if (diagRecords != null)
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = diagRecords[0]["IDAABB"].ToString();
            }
            if (compRecords != null)
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = compRecords[0]["DBEGCOM"].ToString();
            }

            if (diagRecords != null && compRecords != null)
            {
                if (compRecords[0]["DBEGCOM"] != DBNull.Value)
                {
                    myAnswer.textAnswer = (DateTime) diagRecords[0]["IDAABB"] < (DateTime) compRecords[0]["DBEGCOM"] ? diagRecords[0]["IDAABB"].ToString() : compRecords[0]["DBEGCOM"].ToString();
                }
                else
                {
                    myAnswer.textAnswer = diagRecords[0]["IDAABB"].ToString();
                }
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_R_O_P_D_O_D_D_C_H_F_Value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            //Test DISMCLFD<7 and VCHRLEUK=1
            DataRow[] diagRecords1 = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST,
                                                                   "DISMCLFD<'7' AND VCHRLEUK='1'");
            //Test DISMCLFD<'7' AND VCHRLEUK>'1'
            DataRow[] diagRecords2 = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST,
                                                                   "DISMCLFD<'7' AND VCHRLEUK>'1'");
            //Get all assessment records where VRELPROG=2 after current HSCT and before (next HSCT or form due date) 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsAfterCurrHSCTAndBeforeDueLimit(assesmentBs, dateOfTransplant,
                                                                                       RecordSelector.ALL,
                                                                                       "VRELPROG='2'");

            if (diagRecords1 != null)
            {
                if (diagRecords2 != null)
                {
                    //We need to compare both dates to know which is the correct diagnosis.
                    if ((DateTime) diagRecords1[0]["IDAABB"] > (DateTime) diagRecords2[0]["IDAABB"])
                    {
                        if (assesRecords != null)
                        {
                            //Test VRELLEUK=2 or VRELLEUK=NULL
                            for (int i = 0; i <= assesRecords.Length - 1; i++)
                            {
                                if (assesRecords[i]["VRELLEUK"] == DBNull.Value ||
                                    (int) assesRecords[i]["VRELLEUK"] == 2)
                                {
                                    //Copy date DHEMREL
                                    if (assesRecords[i]["DHEMREL"] != DBNull.Value)
                                    {
                                        myAnswer.hasAResponse = true;
                                        myAnswer.freeTextEntry = true;
                                        myAnswer.textAnswer = assesRecords[i]["DHEMREL"].ToString();
                                    }
                                    break; //Stop at first true value
                                }
                            }
                        }
                    }
                    else
                    {
                        if (assesRecords != null)
                        {
                            //Test VRELLEUK=2 or VRELLEUK=NULL
                            for (int i = 0; i <= assesRecords.Length - 1; i++)
                            {
                                if (assesRecords[i]["VRELLEUK"] == DBNull.Value ||
                                    (int) assesRecords[i]["VRELLEUK"] == 2)
                                {
                                    //Copy date IDAABE
                                    myAnswer.hasAResponse = true;
                                    myAnswer.freeTextEntry = true;
                                    myAnswer.textAnswer = assesRecords[i]["IDAABE"].ToString();
                                    break; //Stop at first true value
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (assesRecords != null)
                    {
                        //Test VRELLEUK=2 or VRELLEUK=NULL
                        for (int i = 0; i <= assesRecords.Length - 1; i++)
                        {
                            if (assesRecords[i]["VRELLEUK"] == DBNull.Value ||
                                (int) assesRecords[i]["VRELLEUK"] == 2)
                            {
                                //Copy date DHEMREL
                                if (assesRecords[i]["DHEMREL"] != DBNull.Value)
                                {
                                    myAnswer.hasAResponse = true;
                                    myAnswer.freeTextEntry = true;
                                    myAnswer.textAnswer = assesRecords[i]["DHEMREL"].ToString();
                                }
                                break; //Stop at first true value
                            }
                        }
                    }
                }
            }
            else
            {
                if (diagRecords2 != null)
                {
                    if (assesRecords != null)
                    {
                        //Test VRELLEUK=2 or VRELLEUK=NULL
                        for (int i = 0; i <= assesRecords.Length - 1; i++)
                        {
                            if (assesRecords[i]["VRELLEUK"] == DBNull.Value ||
                                (int) assesRecords[i]["VRELLEUK"] == 2)
                            {
                                //Copy date IDAABE
                                myAnswer.hasAResponse = true;
                                myAnswer.freeTextEntry = true;
                                myAnswer.textAnswer = assesRecords[i]["IDAABE"].ToString();
                                break; //Stop at first true value
                            }
                        }
                    }
                }
                else
                {
                    return myAnswer; //Send the empty object because no answer.
                }
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_R_O_P_D_O_D_D_C_H_D_Value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            //Test DISMCLFD<7 and VCHRLEUK=1
            DataRow[] diagRecords1 = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST,
                                                                   "DISMCLFD<'7' AND VCHRLEUK='1'");
            //Test DISMCLFD<'7' AND VCHRLEUK>'1'
            DataRow[] diagRecords2 = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST,
                                                                   "DISMCLFD<'7' AND VCHRLEUK>'1'");
            //Get all assessment records where (VRELPROG='2' AND VRELLEUK<>'99' AND NOT VRELLEUK IS NULL) after current HSCT and before (next HSCT or form due date) 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsAfterCurrHSCTAndBeforeDueLimit(assesmentBs, dateOfTransplant,
                                                                                       RecordSelector.ALL,
                                                                                       "VRELPROG='2' AND VRELLEUK<>'99' AND NOT VRELLEUK IS NULL");

            if (diagRecords1 != null)
            {
                if (diagRecords2 != null)
                {
                    //We need to compare both dates to know which is the correct diagnosis.
                    if ((DateTime) diagRecords1[0]["IDAABB"] > (DateTime) diagRecords2[0]["IDAABB"])
                    {
                        //Test VRELLEUK='1'
                        for (int i = 0; i <= assesRecords.Length - 1; i++)
                        {
                            if ((int) assesRecords[i]["VRELLEUK"] != 1)
                            {
                                myAnswer.hasAResponse = false; //All must be true
                                return myAnswer;
                            }
                            //Copy date DHEMREL
                            //LAST
                            if (assesRecords[i]["DHEMREL"] != DBNull.Value)
                            {
                                myAnswer.hasAResponse = true;
                                myAnswer.freeTextEntry = true;
                                myAnswer.textAnswer = assesRecords[i]["DHEMREL"].ToString();
                            }
                        }
                    }
                    else
                    {
                        //Test VRELLEUK='1'
                        for (int i = 0; i <= assesRecords.Length - 1; i++)
                        {
                            if ((int) assesRecords[i]["VRELLEUK"] != 1)
                            {
                                myAnswer.hasAResponse = false; //All must be true
                                return myAnswer;
                            }
                            //Copy date IDAABE
                            //LAST
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = assesRecords[i]["IDAABE"].ToString();
                        }
                    }
                }
                else
                {
                    //Test VRELLEUK='1'
                    for (int i = 0; i <= assesRecords.Length - 1; i++)
                    {
                        if ((int) assesRecords[i]["VRELLEUK"] != 1)
                        {
                            myAnswer.hasAResponse = false; //All must be true
                            return myAnswer;
                        }
                        //Copy date DHEMREL
                        //LAST
                        if (assesRecords[i]["DHEMREL"] != DBNull.Value)
                        {
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = assesRecords[i]["DHEMREL"].ToString();
                        }
                    }
                }
            }
            else
            {
                if (diagRecords2 != null)
                {
                    //Test VRELLEUK='1'
                    for (int i = 0; i <= assesRecords.Length - 1; i++)
                    {
                        if ((int) assesRecords[i]["VRELLEUK"] != 1)
                        {
                            myAnswer.hasAResponse = false; //All must be true
                            return myAnswer;
                        }
                        //Copy date IDAABE
                        //LAST
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = assesRecords[i]["IDAABE"].ToString();
                    }
                }
                else
                {
                    return myAnswer; //Send the empty object because no answer.
                }
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_HSCT_DIFF_DIS_IND_yes_value(DateTime dateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get treatment record for the current HSCT
            //Then get value of AACOD2T(1) for this treatment
            //GEt ALL treatment record prior to the current HSCT then get AACOD2T(2) for each
            //Foreach prior treatment, there is at least a mismatch between AACOD2T(1) and AACOD2T(2) , return 'Yes'
            //Else return 'No'
            //Here is the code for only 'Yes' value
            ExBindingSource treatmentBs = GetExBindingSourceByTableName("B2");
            DataRow[] treatRecords = GetTreatmentRecordForCurrentHSCT(treatmentBs, dateOfTransplant,
                                                                      RecordSelector.FIRST, "");
            if (treatRecords != null) //AACOD2T(1)
            {
                DataRow[] priorTreatRecords = GetTreatmentRecordForPreviousHSCT(treatmentBs, dateOfTransplant,
                                                                                RecordSelector.ALL, "");
                if (priorTreatRecords != null) //AACOD2T(2)
                {
                    for (int i = 0; i <= priorTreatRecords.Length - 1; i++)
                    {
                        if (treatRecords[0]["AACOD2T"].ToString() != priorTreatRecords[i]["AACOD2T"].ToString())
                        {
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = "Yes";
                            break; //stop at first true value
                        }
                        myAnswer.hasAResponse = false;
                    }
                }
                else // no previuous treatment record found
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_HSCT_DIFF_DIS_IND_no_value(DateTime dateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get treatment record for the current HSCT
            //Then get value of AACOD2T(1) for this treatment
            //GEt ALL treatment record prior to the current HSCT then get AACOD2T(2) for each
            //Foreach prior treatment, there is at least a mismatch between AACOD2T(1) and AACOD2T(2) , return 'Yes'
            //Else return 'No'
            //Here is the code for only 'No' value
            ExBindingSource treatmentBs = GetExBindingSourceByTableName("B2");
            DataRow[] treatRecords = GetTreatmentRecordForCurrentHSCT(treatmentBs, dateOfTransplant,
                                                                      RecordSelector.FIRST, "");
            if (treatRecords != null) //AACOD2T(1)
            {
                DataRow[] priorTreatRecords = GetTreatmentRecordForPreviousHSCT(treatmentBs, dateOfTransplant,
                                                                                RecordSelector.ALL, "");
                if (priorTreatRecords != null) //AACOD2T(2)
                {
                    for (int i = 0; i <= priorTreatRecords.Length - 1; i++)
                    {
                        if (treatRecords[0]["AACOD2T"].ToString() == priorTreatRecords[i]["AACOD2T"].ToString())
                        {
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = "No";
                        }
                        else
                        {
                            myAnswer.hasAResponse = false;
                        }
                    }
                }
                else //no previous treatment record found
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        //RRA has update value of VCAUSDTH
        public static TranslationAnswer Get_PRM_DTH_RSN_SPEC_Value(DateTime dateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get all assessment records after HSCT 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsAfterADate(assesmentBs, dateOfTransplant, RecordSelector.ALL, "");
            //Patient records
            ExBindingSource patientBs = GetExBindingSourceByTableName("A0");
            DataRowView dRowView = (DataRowView) patientBs[0];
            //if VPATSTAT=1 or VPATSTAT=3
            bool isDied;
            if (assesRecords[0]["VPATSTAT"].ToString() == "1" || assesRecords[0]["VPATSTAT"].ToString() == "3")
            {
                isDied = true;
            }
            else
            {
                isDied = false;
            }
            if (isDied)
            {
                //If VCAUSDTH=77, copy DEACSBMU Value.  If  VCAUSDTH=3, the folowing message should be transmitted: "HSCT related cause not otherwise specified"
                if (dRowView["VCAUSDTH"] != DBNull.Value)
                {
                    if (dRowView["VCAUSDTH"].ToString() == "77")
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = dRowView["DEACSBMU"].ToString();
                    }
                    else if (dRowView["VCAUSDTH"].ToString() == "3")
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = "HSCT related cause not otherwise specified";
                    }
                    else
                    {
                        myAnswer.hasAResponse = false;
                    }
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        // ?TO DO?
        public static TranslationAnswer Get_DTH_RSN_CNF_AUTP_IND_Value()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            return myAnswer;
        }

        //RRA 2400 - functions to check with DPA
        /// <summary>
        ///   Get the last diagnosis. If this one is coded as not MDS (DISMCLFD != '6'), copy the corresponding date from BB table Else if diagnosis is coded as MDS (DISMCLFD ='6'), verify if transformation has occured in assesment table before the date of HSCT then copy the date DATTRAN from BE table
        /// </summary>
        /// <param name="dateOfTransplant"> </param>
        /// <returns> </returns>
        public static TranslationAnswer Get_HSCT_PRIM_DIAG_DT_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DateTime myDateResult;

            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");
            ////Test if DISMCLFD<>'6' or DISMCLFD=='6'
            bool isMDS = diagRecords[0]["DISMCLFD"].ToString() == "6";


            //Get all assessment records before date of HSCT 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                         RecordSelector.ALL, "");

            if (!isMDS)
            {
                //copy the date from IDAABB
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myDateResult = Convert.ToDateTime(diagRecords[0]["IDAABB"].ToString());
                myAnswer.textAnswer = myDateResult.ToString("yyyy-MM-dd");
            }
            else
            {
                for (int i = 0; i <= assesRecords.Length - 1; i++)
                {
                    //where MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9
                    if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                        assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                    {
                        //Copy date from BE
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        if (assesRecords[i]["DATTRAN"] != DBNull.Value)
                        {
                            myDateResult = Convert.ToDateTime(assesRecords[i]["DATTRAN"].ToString());
                            myAnswer.textAnswer = myDateResult.ToString("yyyy-MM-dd");
                        }
                        //myAnswer.textAnswer = "";
                    }
                }
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_HSCT_PRI_DIS_TYP_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.FIRST,
                                                                  "");
            //Get all assessment records before date of HSCT 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                         RecordSelector.ALL, "");

            //Where  (VACLEUK=1 or VSOLTUMO=97) 
            if (diagRecords != null)
            {
                if (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Acute myelogenous leukemia (AML or ANLL)";
                }
                else
                {
                    for (int i = 0; i <= assesRecords.Length - 1; i++)
                    {
                        //if VMDSMPS=1 AND (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                        if (diagRecords[0]["VMDSMPS"].ToString() == "1" &&
                            (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                             assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9"))
                        {
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = "Acute myelogenous leukemia (AML or ANLL)";
                        }
                        else
                        {
                            myAnswer.hasAResponse = false;
                        }
                    }
                }
            }
            else
            {
                throw new EbmtDALException("diagRecords is null!");
            }
            return myAnswer;
        }

        /// <summary>
        ///   up by RRA on 12/29/2011. Un patient est soit AML soit AML from MDS
        /// </summary>
        /// <param name="dateOfTransplant"> </param>
        /// <returns> </returns>
        public static TranslationAnswer Get_TX_REL_AML_DX_DX_I_3_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //if  (VACLEUK=1 or VSOLTUMO=97) & VSECORIG=2
            string isAMLorGranulocyticSarcoma = "";
            if (diagRecords[0]["VSECORIG"].ToString() == "2" &&
                (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97"))
            {
                isAMLorGranulocyticSarcoma = "Yes";
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
                myAnswer.textAnswer = isAMLorGranulocyticSarcoma;
            } //(VACLEUK=1 or VSOLTUMO=97) & VSECORIG=1
            else if (diagRecords[0]["VSECORIG"].ToString() == "1" &&
                     (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97"))
            {
                isAMLorGranulocyticSarcoma = "No";
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
                myAnswer.textAnswer = isAMLorGranulocyticSarcoma;
            } //(VACLEUK=1 or VSOLTUMO=97) & VSECORIG=99 or null
            else if ((diagRecords[0]["VSECORIG"].ToString() == "99" ||
                      diagRecords[0]["VSECORIG"].ToString() == "null") &&
                     (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97"))
            {
                isAMLorGranulocyticSarcoma = "Unknown";
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
                myAnswer.textAnswer = isAMLorGranulocyticSarcoma;
            }
            else
            {
                myAnswer.hasAResponse = false;
            }

            //Get all assessment records before date of HSCT 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                         RecordSelector.ALL, "");

            if (assesRecords != null && myAnswer.hasAResponse == false)
            {
                for (int i = 0; i <= assesRecords.Length - 1; i++)
                {
                    //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                    if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                        assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = false;
                        myAnswer.textAnswer = isAMLorGranulocyticSarcoma;
                        //break; //stop at first true value   
                    }
                    else
                    {
                        myAnswer.hasAResponse = false;
                    }
                }
            }

            return myAnswer;
        }

        /// <summary>
        ///   Therapy-Related Acute Myeloid Leukemia Etiology Occurrence Yes No Character Indicator
        /// </summary>
        /// <param name="dateOfTransplant"> </param>
        /// <returns> </returns>
        public static TranslationAnswer Get_TX_AML_ETLGY_OCR_IND_A_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //if  (VACLEUK=1 or VSOLTUMO=97) & (DISSECD1=1 or DISSECD1=3)
            string myDiagResult = "";
            if ((diagRecords[0]["DISSECD1"].ToString() == "1" || diagRecords[0]["DISSECD1"].ToString() == "3") &&
                (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97"))
            {
                myDiagResult = "Yes"; //GetEBMTVariableValueDescription("DISSECD1", 214, 1);
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
                myAnswer.textAnswer = myDiagResult;
            }

            //Get all assessment records before date of HSCT 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                         RecordSelector.ALL, "");

            if (myAnswer.hasAResponse == false && assesRecords != null)
            {
                for (int i = 0; i <= assesRecords.Length - 1; i++)
                {
                    //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                    if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                        assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = false;
                        myAnswer.textAnswer = myDiagResult;
                    }
                    else
                    {
                        myAnswer.hasAResponse = false;
                    }
                }
            }

            return myAnswer;
        }

        public static TranslationAnswer Get_TX_AML_ETLGY_OCR_IND_B_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //if  (VACLEUK=1 or VSOLTUMO=97) & (DISSECD1=2 or DISSECD1=3)
            string myDiagResult = "";
            if ((diagRecords[0]["DISSECD1"].ToString() == "2" || diagRecords[0]["DISSECD1"].ToString() == "3") &&
                (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97"))
            {
                myDiagResult = "Yes"; // GetEBMTVariableValueDescription("DISSECD1", 214, 2);
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
                myAnswer.textAnswer = myDiagResult;
            }

            //Get all assessment records before date of HSCT 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                         RecordSelector.ALL, "");

            if (myAnswer.hasAResponse == false && assesRecords != null)
            {
                for (int i = 0; i <= assesRecords.Length - 1; i++)
                {
                    //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                    if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                        assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = false;
                        myAnswer.textAnswer = myDiagResult;
                    }
                    else
                    {
                        myAnswer.hasAResponse = false;
                    }
                }
            }

            return myAnswer;
        }

        public static TranslationAnswer Get_TX_AML_ETLGY_OCR_IND_C_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //if  (VACLEUK=1 or VSOLTUMO=97) & ( DISSECD1=99)
            string myDiagResult = "";
            if (diagRecords[0]["DISSECD1"].ToString() == "99" &&
                (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97"))
            {
                myDiagResult = "Yes"; // GetEBMTVariableValueDescription("DISSECD1", 214, 99);
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
                myAnswer.textAnswer = myDiagResult;
            }

            //Get all assessment records before date of HSCT 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                         RecordSelector.ALL, "");

            if (myAnswer.hasAResponse == false && assesRecords != null)
            {
                for (int i = 0; i <= assesRecords.Length - 1; i++)
                {
                    //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                    if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                        assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = myDiagResult;
                    }
                    else
                    {
                        myAnswer.hasAResponse = false;
                    }
                }
            }

            return myAnswer;
        }

        /// <summary>
        ///   Algorithm: We first check the first row ,If the 1st row does not match, check the second row. RRA February 10th 2012: If there are no records with the drug -> unknown
        /// </summary>
        /// <param name="dateOfTransplant"> </param>
        /// <returns> </returns>
        public static TranslationAnswer Get_AML_PR_IMTNB_TX_IND3_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");
            //if ( (VACLEUK=1 or VSOLTUMO=97) )
            bool isAMLorGranulocyticSarcoma;
            if ((diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97"))
            {
                isAMLorGranulocyticSarcoma = true;
            }
            else
            {
                isAMLorGranulocyticSarcoma = false;
            }

            //function for condition on drugRecords here
            TranslationAnswer myAnswer = ConditionResultFromDrugRecord(dateOfTransplant, isAMLorGranulocyticSarcoma);
            //Get all assessment records before date of HSCT 
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                         RecordSelector.ALL, "");

            if (myAnswer.hasAResponse == false && assesRecords != null)
            {
                bool isDisTransformedfromMDS = false; // Disease transformation has occured
                for (int i = 0; i <= assesRecords.Length - 1; i++)
                {
                    //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                    if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                        assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                    {
                        isDisTransformedfromMDS = true;
                        break; //stop at first true value
                    }
                }
                //in all drug records before current HSCT
                myAnswer = ConditionResultFromDrugRecord(dateOfTransplant, isDisTransformedfromMDS);
            }
            else
            {
                myAnswer.hasAResponse = false;
            }


            if (myAnswer.hasAResponse == false && isAMLorGranulocyticSarcoma)
                //rg 2012-04-19 only applies to AML patients
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = "Unknown";
            }

            return myAnswer;
        }

        private static TranslationAnswer ConditionResultFromDrugRecord(DateTime dateOfTransplant, bool isAML)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            ExBindingSource drugBs = GetExBindingSourceByTableName("C3");
            DataRow[] drugRecords = GetDrugRecordsBeforeHSCT(drugBs, dateOfTransplant, RecordSelector.ALL, "");
            //Check if at least one row is verifying this following condition: IDAABCCD=32 and DRUGDONE=2 in drug table
            if (isAML && drugRecords != null)
            {
                for (int j = 0; j <= drugRecords.Length - 1; j++)
                {
                    //if IDAABCCD=32 and (DRUGDONE=2 OR DRUGDONE IS NULL) - GC5400-3-055
                    if (drugRecords[j]["IDAABCCD"].ToString() == "32" &&
                        (drugRecords[j]["DRUGDONE"].ToString() == "2"))
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = "Yes";
                        break; //stop at first true value
                    }
                        //(IDAABCCD=32 or IDAABCCD=76) and DRUGDONE=1
                    if ((drugRecords[j]["IDAABCCD"].ToString() == "32" ||
                         drugRecords[j]["IDAABCCD"].ToString() == "76") &&
                        drugRecords[j]["DRUGDONE"].ToString() == "1")
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = "No";
                        break; //stop at first true value
                    }
                        //(IDAABCCD=32 or IDAABCCD=76) and (DRUGDONE=99 or DRUGDONE=null)
                    if ((drugRecords[j]["IDAABCCD"].ToString() == "32" ||
                         drugRecords[j]["IDAABCCD"].ToString() == "76") &&
                        (drugRecords[j]["DRUGDONE"].ToString() == "99"))
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = "Unknown";
                        break; //stop at first true value
                    }
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_AML_TRN_ALEUK_STAT_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //if  (VACLEUK=1 or VSOLTUMO=97)
            bool isAMLorGranulocyticSarcoma = (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97");

            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] CurrentAssesRecords = GetCurrentHSCTAssesmentRecord(assesmentBs, dateOfTransplant);
            if (isAMLorGranulocyticSarcoma)
            {
                //during the assessment record for current HSCT 
                //RRA 
                myAnswer = ConditionResultFromAssessmentRecord(CurrentAssesRecords);
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            //second row
            if (myAnswer.hasAResponse == false)
            {
                DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                             RecordSelector.ALL, "");
                bool isDisTransformedfromMDS = false; // Disease transformation from MDS has occured

                if (assesRecords != null)
                {
                    for (int i = 0; i <= assesRecords.Length - 1; i++)
                    {
                        //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                        if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                            assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                        {
                            isDisTransformedfromMDS = true;
                            break; //stop at first true value
                        }
                    }
                    if (isDisTransformedfromMDS)
                    {
                        myAnswer = ConditionResultFromAssessmentRecord(assesRecords);
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            return myAnswer;
        }

        private static TranslationAnswer ConditionResultFromAssessmentRecord(DataRow[] _CurrentAssesRecords)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();


            if (_CurrentAssesRecords != null)
            {
                if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "70")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Never treated"; // GetEBMTVariableValueDescription("VDISESTA", 169, 70);
                }
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "10")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Primary Induction Failure (PIF)";
                    //GetEBMTVariableValueDescription("VDISESTA", 169, 10);
                }
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Complete remission"; //GetEBMTVariableValueDescription("VDISESTA", 169, 30);
                }
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "50")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Relapse"; // GetEBMTVariableValueDescription("VDISESTA", 169, 50);
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_AML_CYT_CR_Y_N_U_IND_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //if  (VACLEUK=1 or VSOLTUMO=97)
            bool isAMLorGranulocyticSarcoma = (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97");

            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] CurrentAssesRecords = GetCurrentHSCTAssesmentRecord(assesmentBs, dateOfTransplant);
            if (isAMLorGranulocyticSarcoma)
            {
                //during the assessment record for current HSCT 
                //RRA 
                myAnswer = ConditionResultFromAssessmentRecord_CYT_CR(CurrentAssesRecords);
            }
            else
            {
                myAnswer.hasAResponse = false;
            }

            //second row
            if (myAnswer.hasAResponse == false)
            {
                DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                             RecordSelector.ALL, "");
                bool isDisTransformedfromMDS = false; // Disease transformation from MDS has occured
                if (assesRecords != null)
                {
                    for (int i = 0; i <= assesRecords.Length - 1; i++)
                    {
                        //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                        if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                            assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                        {
                            isDisTransformedfromMDS = true;
                            break; //stop at first true value
                        }
                    }
                    if (isDisTransformedfromMDS)
                    {
                        myAnswer = ConditionResultFromAssessmentRecord_CYT_CR(CurrentAssesRecords);
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            return myAnswer;
        }

        private static TranslationAnswer ConditionResultFromAssessmentRecord_CYT_CR(DataRow[] _CurrentAssesRecords)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();


            if (_CurrentAssesRecords != null)
            {
                //VDISESTA=30 and VCYTOGRE=2
                if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30" &&
                    _CurrentAssesRecords[0]["VCYTOGRE"].ToString() == "2")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Yes";
                }
                    //VDISESTA=30 and VCYTOGRE=1
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30" &&
                         _CurrentAssesRecords[0]["VCYTOGRE"].ToString() == "1")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "No";
                }
                    //VDISESTA=30 and (VCYTOGRE=3 or VCYTOGRE=99 or VCYTOGRE=null)
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30" &&
                         (_CurrentAssesRecords[0]["VCYTOGRE"].ToString() == "3" ||
                          _CurrentAssesRecords[0]["VCYTOGRE"].ToString() == "99" ||
                          _CurrentAssesRecords[0]["VCYTOGRE"].ToString() == string.Empty))
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Unknown";
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_AML_MOL_CR_Y_N_U_IND_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //if  (VACLEUK=1 or VSOLTUMO=97)
            bool isAMLorGranulocyticSarcoma = (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97");

            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] CurrentAssesRecords = GetCurrentHSCTAssesmentRecord(assesmentBs, dateOfTransplant);
            if (isAMLorGranulocyticSarcoma)
            {
                //during the assessment record for current HSCT 
                //RRA 
                myAnswer = ConditionResultFromAssessmentRecord_MOL_CR(CurrentAssesRecords);
            }
            else
            {
                myAnswer.hasAResponse = false;
            }

            //second row
            if (myAnswer.hasAResponse == false)
            {
                DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                             RecordSelector.ALL, "");
                bool isDisTransformedfromMDS = false; // Disease transformation from MDS has occured
                if (assesRecords != null)
                {
                    for (int i = 0; i <= assesRecords.Length - 1; i++)
                    {
                        //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                        if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                            assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                        {
                            isDisTransformedfromMDS = true;
                            break; //stop at first true value
                        }
                    }
                    if (isDisTransformedfromMDS)
                    {
                        myAnswer = ConditionResultFromAssessmentRecord_MOL_CR(CurrentAssesRecords);
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            return myAnswer;
        }

        private static TranslationAnswer ConditionResultFromAssessmentRecord_MOL_CR(DataRow[] _CurrentAssesRecords)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();


            if (_CurrentAssesRecords != null)
            {
                //VDISESTA=30 and VMOLECRE=2
                if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30" &&
                    _CurrentAssesRecords[0]["VMOLECRE"].ToString() == "2")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Yes";
                }
                    //VDISESTA=30 and VMOLECRE=1
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30" &&
                         _CurrentAssesRecords[0]["VMOLECRE"].ToString() == "1")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "No";
                }
                    //VDISESTA=30 and (VMOLECRE=3 or VMOLECRE=99 or VMOLECRE=null)
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30" &&
                         (_CurrentAssesRecords[0]["VMOLECRE"].ToString() == "3" ||
                          _CurrentAssesRecords[0]["VMOLECRE"].ToString() == "99" ||
                          _CurrentAssesRecords[0]["VMOLECRE"].ToString() == string.Empty))
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Unknown";
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_AML_TRN_CR_DS_ST_CT_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //if  (VACLEUK=1 or VSOLTUMO=97)
            bool isAMLorGranulocyticSarcoma = (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97");
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] CurrentAssesRecords = GetCurrentHSCTAssesmentRecord(assesmentBs, dateOfTransplant);
            if (isAMLorGranulocyticSarcoma)
            {
                //during the assessment record for current HSCT 
                //RRA 
                myAnswer = ConditionResultFromAssessmentRecord_CR_DS_ST(CurrentAssesRecords);
            }
            else
            {
                myAnswer.hasAResponse = false;
            }

            //second row
            if (myAnswer.hasAResponse == false)
            {
                DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                             RecordSelector.ALL, "");
                bool isDisTransformedfromMDS = false; // Disease transformation from MDS has occured
                if (assesRecords != null)
                {
                    for (int i = 0; i <= assesRecords.Length - 1; i++)
                    {
                        //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                        if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                            assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                        {
                            isDisTransformedfromMDS = true;
                            break; //stop at first true value
                        }
                    }
                    if (isDisTransformedfromMDS)
                    {
                        myAnswer = ConditionResultFromAssessmentRecord_CR_DS_ST(CurrentAssesRecords);
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            return myAnswer;
        }

        private static TranslationAnswer ConditionResultFromAssessmentRecord_CR_DS_ST(DataRow[] _CurrentAssesRecords)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();


            if (_CurrentAssesRecords != null)
            {
                //VDISESTA=30 and VNUMSTM=1
                if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30" &&
                    _CurrentAssesRecords[0]["VNUMSTM"].ToString() == "1")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = false;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VNUMSTM", 923, 1);
                }
                    //VDISESTA=30 and VNUMSTM=2
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30" &&
                         _CurrentAssesRecords[0]["VNUMSTM"].ToString() == "2")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = false;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VNUMSTM", 923, 2);
                }
                    //VDISESTA=30 and VNUMSTM=3
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "30" &&
                         _CurrentAssesRecords[0]["VNUMSTM"].ToString() == "3")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = false;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VNUMSTM", 923, 3);
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_AML_TRN_RLPS_ST_CT_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //if  (VACLEUK=1 or VSOLTUMO=97)
            bool isAMLorGranulocyticSarcoma = (diagRecords[0]["VACLEUK"].ToString() == "1" || diagRecords[0]["VSOLTUMO"].ToString() == "97");
            ExBindingSource assesmentBs = GetExBindingSourceByTableName("B4");
            DataRow[] CurrentAssesRecords = GetCurrentHSCTAssesmentRecord(assesmentBs, dateOfTransplant);
            if (isAMLorGranulocyticSarcoma)
            {
                //during the assessment record for current HSCT 
                //RRA 
                myAnswer = ConditionResultFromAssessmentRecord_TRN_RLPS_ST(CurrentAssesRecords);
            }
            else
            {
                myAnswer.hasAResponse = false;
            }


            //second row
            if (myAnswer.hasAResponse == false)
            {
                DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesmentBs, dateOfTransplant,
                                                                             RecordSelector.ALL, "");
                bool isDisTransformedfromMDS = false; // Disease transformation from MDS has occured
                if (assesRecords != null)
                {
                    for (int i = 0; i <= assesRecords.Length - 1; i++)
                    {
                        //if  (MDSSTAG=18 or VMDS=50 or MDMPSTAG=2 or VMPS=9 )
                        if (assesRecords[i]["MDSSTAG"].ToString() == "18" || assesRecords[i]["VMDS"].ToString() == "50" ||
                            assesRecords[i]["MDMPSTAG"].ToString() == "2" || assesRecords[i]["VMPS"].ToString() == "9")
                        {
                            isDisTransformedfromMDS = true;
                            break; //stop at first true value
                        }
                    }
                    if (isDisTransformedfromMDS)
                    {
                        myAnswer = ConditionResultFromAssessmentRecord_TRN_RLPS_ST(CurrentAssesRecords);
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            return myAnswer;
        }

        private static TranslationAnswer ConditionResultFromAssessmentRecord_TRN_RLPS_ST(DataRow[] _CurrentAssesRecords)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();

            if (_CurrentAssesRecords != null)
            {
                //VDISESTA=50 and VNUMSTM=1
                if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "50" &&
                    _CurrentAssesRecords[0]["VNUMSTM"].ToString() == "1")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = false;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VNUMSTM", 923, 1);
                }
                    //VDISESTA=50 and VNUMSTM=2
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "50" &&
                         _CurrentAssesRecords[0]["VNUMSTM"].ToString() == "2")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = false;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VNUMSTM", 923, 2);
                }
                    //VDISESTA=50 and VNUMSTM=3
                else if (_CurrentAssesRecords[0]["VDISESTA"].ToString() == "50" &&
                         _CurrentAssesRecords[0]["VNUMSTM"].ToString() == "3")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = false;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VNUMSTM", 923, 3);
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }


        public static TranslationAnswer Get_TCELL_NHL_CLASS_SP_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");
            // check if DISMCLFD=3 
            bool isLympho;
            if (diagRecords[0]["DISMCLFD"].ToString() == "3") // && diagRecords[0]["VSOLTUMO"].ToString() == "97"))
            {
                //and ((VREALCLS<200 and VREALCLS<>60 and VREALCLS<>140) or VREALCLS=300)
                if (((int) diagRecords[0]["VREALCLS"] < 200 && (int) diagRecords[0]["VREALCLS"] != 60 &&
                     (int) diagRecords[0]["VREALCLS"] != 140) || (int) diagRecords[0]["VREALCLS"] == 300)
                {
                    isLympho = true;
                }
                else
                {
                    isLympho = false;
                }
            }
            else
            {
                isLympho = false;
            }

            if (isLympho)
            {
//if VREALCLS = 105 we copy the value of VDIAGTX
                if ((int) diagRecords[0]["VREALCLS"] == 105)
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VDIAGTX", 124, 105);
                }
                    //if VREALCLS = 145 we copy the label description
                else if ((int) diagRecords[0]["VREALCLS"] == 145)
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "Label description of VREALCLS"; // TO DO
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }

            return myAnswer;
        }

        public static TranslationAnswer Get_O_DZ_DX_SPEC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //DISMCLFD=12 or DISMCLFD=13 or DISMCLFD=88
            if (diagRecords[0]["DISMCLFD"].ToString() == "12" || diagRecords[0]["DISMCLFD"].ToString() == "13")
            {
                int iDISMValue = (int) diagRecords[0]["DISMCLFD"];
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = GetEBMTVariableValueDescription("DISMCLFD", 60, iDISMValue);
                //"Label description of DISMCLFD"; // TO DO
            }
            else if (diagRecords[0]["DISMCLFD"].ToString() == "88")
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = GetEBMTVariableValueDescription("VDIAGTX", 124, 105);
            }
            else
            {
                myAnswer.hasAResponse = false;
            }

            return myAnswer;
        }

        public static TranslationAnswer Get_OTHR_CNCR_CLS_DX_SPC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //DISMCLFD=5 and VSOLTUMO<>80 and VSOLTUMO<>97 and VSOLTUMO<>999
            bool isSolidTumor;
            if (diagRecords[0]["DISMCLFD"].ToString() == "5" && diagRecords[0]["VSOLTUMO"].ToString() != "80" &&
                diagRecords[0]["VSOLTUMO"].ToString() != "97" && diagRecords[0]["VSOLTUMO"].ToString() != "999")
                // && diagRecords[0]["VSOLTUMO"].ToString() == "97"))
            {
                isSolidTumor = true;
            }
            else
            {
                isSolidTumor = false;
            }
            //VSOLTUMO=777 or VSOLTUMO=92 or VSOLTUMO=93 or VSOLTUMO=94 or VSOLTUMO=46 or VSOLTUMO=50 or VSOLTUMO=90
            // If  VSOLTUMO=777, copy VDIAGTX value, but if VSOLTUMO= any other value allowed in the condition,copy VSOLTUMO label description
            if (isSolidTumor)
            {
                if (diagRecords[0]["VSOLTUMO"].ToString() == "777")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                }
                else
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = "VSOLTUMO label description"; // TO DO
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_O_CTYPNA_SNDRM_SPEC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //BMFSACQ=1 or BMFSACQ=2 or BMFSACQ=3 or BMFSACQ=4 or BMFSACQ=5 or BMFSACQ=77
            //If BMFSACQ=4 copy label description ; if BMFSACQ=77 or VSAATYPE=77 copy VDIAGTX value

            if (diagRecords[0]["BMFSACQ"].ToString() == "4")
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = GetEBMTVariableValueDescription("BMFSACQ", 149, 77);
            }
            else if (diagRecords[0]["BMFSACQ"].ToString() == "77" || diagRecords[0]["VSAATYPE"].ToString() == "77")
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
            }
            else
            {
                myAnswer.hasAResponse = false;
            }

            return myAnswer;
        }

        public static TranslationAnswer Get_OTHR_GNTC_ANM_CLS_SP_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //BMFSGEN=1 or BMFSGEN=2 or BMFSGEN=3 or BMFSGEN=4 or BMFSGEN=5 or BMFSGEN=77 or DISMCLFD=11 
            // If  or BMFSGEN=77, copy VDIAGTX value (table ID BB). But if BMFSGEN=4 or BMFSGEN=5, copy BMFSGEN label description

            if (diagRecords[0]["BMFSGEN"].ToString() == "4")
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = GetEBMTVariableValueDescription("BMFSGEN", 156, 4);
            }
            else if (diagRecords[0]["BMFSGEN"].ToString() == "5")
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = GetEBMTVariableValueDescription("BMFSGEN", 156, 5);
            }
            else if (diagRecords[0]["BMFSGEN"].ToString() == "77")
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
            }
            else
            {
                myAnswer.hasAResponse = false;
            }

            return myAnswer;
        }

        public static TranslationAnswer Get_CNG_MTB_DS_OTR_TP_SP_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //INHDIS=2 or VINBERR3=41 
            // If VINBERR2=30 or 32, or 33 or 34 or 35 or 36 or 63 or 80 copy VINBERR2 label description, but if VINBERR2= 777, copy VDIAGTX value (table ID BB).
            bool isInheritedDisorders;
            if (diagRecords[0]["INHDIS"].ToString() == "2" || diagRecords[0]["VINBERR3"].ToString() == "41")
            {
                isInheritedDisorders = true;
            }
            else
            {
                isInheritedDisorders = false;
            }

            if (isInheritedDisorders)
            {
                switch (diagRecords[0]["VINBERR2"].ToString())
                {
                    case "30":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 142, 30);
                        break;
                    case "32":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 142, 32);
                        break;
                    case "33":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 142, 33);
                        break;
                    case "34":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 142, 34);
                        break;
                    case "35":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 142, 35);
                        break;
                    case "36":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 142, 36);
                        break;
                    case "63":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 142, 63);
                        break;
                    case "80":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 142, 80);
                        break;
                    case "777":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                        break;

                    default:
                        myAnswer.hasAResponse = false;
                        break;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }


            return myAnswer;
        }

        public static TranslationAnswer Get_IMN_DS_O_SCID_CLS_SP_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //INHDIS=1
            //IMMDEF=16 or IMMDEF=17 or IMMDEF=25 or IMMDEF=26 or IMMDEF=27 or IMMDEF=37
            //  If IMMDEF=16 or 17 or 25 or 26 or 27 copy  label description, but if IMMDEF= 777, copy IMMDEF label description, but if IMMDEF=37, copy VDIAGTX value (table ID BB).
            bool isInheritedDisorders = diagRecords[0]["INHDIS"].ToString() == "1";

            if (isInheritedDisorders)
            {
                switch (diagRecords[0]["IMMDEF"].ToString())
                {
                    case "16":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 16);
                        break;
                    case "17":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 17);
                        break;
                    case "25":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 25);
                        break;
                    case "26":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 26);
                        break;
                    case "27":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 27);
                        break;
                    case "35":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 106, 35);
                        break;
                    case "36":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 106, 36);
                        break;
                    case "63":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 106, 63);
                        break;
                    case "80":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("VINBERR2", 106, 80);
                        break;
                    case "777":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                        break;

                    default:
                        myAnswer.hasAResponse = false;
                        break;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }


            return myAnswer;
        }

        public static TranslationAnswer Get_IMN_DSRDR_O_CLS_SPEC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //INHDIS=1
            //IMMDEF=11 or IMMDEF=12 or IMMDEF=13 or IMMDEF=21 or IMMDEF=22 or IMMDEF=23 or IMMDEF=32 or IMMDEF=50 or IMMDEF=57 or or IMMDEF=133 or IMMDEF=140 or IMMDEF=141 or IMMDEF=777
            //If IMMDEF=11 or 12 or 13 or  21 or 22 or 23 or 32 or 50 or 57 or 33 or 140 or 141, copy  label description, but if IMMDEF= 777, copy VDIAGTX value (table ID BB).
            bool isInheritedDisorders = diagRecords[0]["INHDIS"].ToString() == "1";

            if (isInheritedDisorders)
            {
                switch (diagRecords[0]["IMMDEF"].ToString())
                {
                    case "11":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 11);
                        break;
                    case "12":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 12);
                        break;
                    case "13":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 13);
                        break;
                    case "21":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 21);
                        break;
                    case "22":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 22);
                        break;
                    case "23":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 23);
                        break;
                    case "32":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 32);
                        break;
                    case "50":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 50);
                        break;
                    case "57":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 57);
                        break;
                    case "33":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 33);
                        break;
                    case "140":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 140);
                        break;
                    case "141":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = GetEBMTVariableValueDescription("IMMDEF", 106, 141);
                        break;
                    case "777":
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                        break;

                    default:
                        myAnswer.hasAResponse = false;
                        break;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }


            return myAnswer;
        }

        public static TranslationAnswer Get_O_CNTV_TSE_DS_TP_SPC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //DISMCLFD=10
            //VAUTOIM2=77 or VAUTOIM2=99
            // If VAUTOIM2=99, copy VAUTOIM2 label description, but if VAUTOIM2= 77, copy VDIAGTX value (table ID BB)
            bool isAutoImDis = diagRecords[0]["DISMCLFD"].ToString() == "10";
            if (isAutoImDis)
            {
                if (diagRecords[0]["VAUTOIM2"].ToString() == "99")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VAUTOIM2", 122, 99);
                }
                else if (diagRecords[0]["VAUTOIM2"].ToString() == "77")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_VAS_OTHR_CLS_DX_SPC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //DISMCLFD=10
            //'VAUTOIM3=77 or VAUTOIM3=99
            // Exception:  If VAUTOIM3=99, copy VAUTOIM3 label description, but if VAUTOIM3= 77, copy VDIAGTX value (table ID BB)
            bool isAutoImDis = diagRecords[0]["DISMCLFD"].ToString() == "10";
            if (isAutoImDis)
            {
                if (diagRecords[0]["VAUTOIM3"].ToString() == "99")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VAUTOIM3", 123, 99);
                }
                else if (diagRecords[0]["VAUTOIM3"].ToString() == "77")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_ARTH_OTHR_CLS_SPEC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //DISMCLFD=10
            //'VAUTOIM4=77 or VAUTOIM4=99
            //  If VAUTOIM4=99, copy VAUTOIM4 label description, but if VAUTOIM4= 77, copy VDIAGTX value (table ID BB).
            bool isAutoImDis = diagRecords[0]["DISMCLFD"].ToString() == "10";
            if (isAutoImDis)
            {
                if (diagRecords[0]["VAUTOIM4"].ToString() == "99")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VAUTOIM4", 126, 99);
                }
                else if (diagRecords[0]["VAUTOIM4"].ToString() == "77")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_NEURO_AUTO_O_CLS_SPC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //DISMCLFD=10
            //'VAUTOIM5=77 or VAUTOIM5=99
            //  If VAUTOIM5=99, copy VAUTOIM4 label description, but if VAUTOIM5= 77, copy VDIAGTX value (table ID BB).
            bool isAutoImDis = diagRecords[0]["DISMCLFD"].ToString() == "10";
            if (isAutoImDis)
            {
                if (diagRecords[0]["VAUTOIM5"].ToString() == "99")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VAUTOIM5", 126, 99);
                }
                else if (diagRecords[0]["VAUTOIM5"].ToString() == "77")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_CYTO_AUTO_O_CLS_SPC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //DISMCLFD=10
            //VAUTOIM6=3  or VAUTOIM6=4 or VAUTOIM6=77 or VAUTOIM6=99
            //  If VAUTOIM6=99 or 3 or 4, copy VAUTOIM6 label description, but if VAUTOIM6= 77, copy VDIAGTX value (table ID BB).
            bool isAutoImDis = diagRecords[0]["DISMCLFD"].ToString() == "10";
            if (isAutoImDis)
            {
                if (diagRecords[0]["VAUTOIM6"].ToString() == "99")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VAUTOIM6", 126, 99);
                }
                else if (diagRecords[0]["VAUTOIM6"].ToString() == "77")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_BWL_AUTO_O_CLS_SPEC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //DISMCLFD=10
            //'VAUTOIM7=77 or VAUTOIM7=99
            //   If VAUTOIM7=99, copy VAUTOIM7 label description, but if VAUTOIM7= 77, copy VDIAGTX value (table ID BB)
            bool isAutoImDis = diagRecords[0]["DISMCLFD"].ToString() == "10";
            if (isAutoImDis)
            {
                if (diagRecords[0]["VAUTOIM7"].ToString() == "99")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = GetEBMTVariableValueDescription("VAUTOIM7", 126, 99);
                }
                else if (diagRecords[0]["VAUTOIM7"].ToString() == "77")
                {
                    myAnswer.hasAResponse = true;
                    myAnswer.freeTextEntry = true;
                    myAnswer.textAnswer = diagRecords[0]["VDIAGTX"].ToString();
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        //RRA 20-09-2011 
        public static TranslationAnswer Get_RMAB_PRP_REG_TYPE_value(DateTime DateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get treatment record for current HSCT
            ExBindingSource treatmentBs = GetExBindingSourceByTableName("B2");
            DataRow[] treatRecords = GetHSCTreatmentRecord(treatmentBs, DateOfTransplant);
            //All drug records for current HSCT where REASDRUG = 9 AND IDAABCCD <> NULL
            ExBindingSource drugBs = GetExBindingSourceByTableName("C3");
            const string drugFilter = "REASDRUG = 9 AND IDAABCCD IS NOT NULL";
            DataRow[] drugRecords = GetDrugRecordsForCurrentHSCT(drugBs, DateOfTransplant, RecordSelector.ALL,
                                                                 drugFilter);
            //PreCondition is : 
            //VCONDITI=2 AND 
            //(IDAABCCD = 691 OR IDAABCCD = 692 OR 
            //(OTHECHEM<>NULL or (IDAABCCD>=776 and IDAABCCD<=779) or (IDAABCCD>=600 and IDAABCCD<=665 and IDAABCCD<>650)) and RADIOLB=2)
            // IDAABCCD <> 692              /* is the corresponding condition for the answer 'No' */
            if (treatRecords != null)
            {
                if (treatRecords[0]["VCONDITI"].ToString() == "2")
                {
                    if (drugRecords != null)
                    {
                        if (drugRecords[0]["IDAABCCD"].ToString() != "692")
                        {
                            if (drugRecords[0]["IDAABCCD"].ToString() == "691")
                            {
                                myAnswer.hasAResponse = true;
                            }
                            else if (drugRecords[0]["RADIOLB"].ToString() == "2")
                            {
                                if (drugRecords[0]["OTHECHEM"].ToString() != "NULL" ||
                                    ((int) drugRecords[0]["IDAABCCD"] >= 776 && (int) drugRecords[0]["IDAABCCD"] >= 779) ||
                                    ((int) drugRecords[0]["IDAABCCD"] >= 600 && (int) drugRecords[0]["IDAABCCD"] <= 665 &&
                                     (int) drugRecords[0]["IDAABCCD"] != 650))
                                {
                                    myAnswer.hasAResponse = true;
                                }
                                else
                                {
                                    myAnswer.hasAResponse = false;
                                }
                            }
                            else
                            {
                                myAnswer.hasAResponse = false;
                            }
                        }
                        else
                        {
                            myAnswer.hasAResponse = false;
                        }
                    }
                    else
                    {
                        myAnswer.hasAResponse = false; //drugRecords is null
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            return myAnswer;
        }

        //RGU 21-11-2011
        public static TranslationAnswer Get_MAB_PRP_REG_TYPE_value(DateTime DateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get treatment record for current HSCT
            ExBindingSource treatmentBs = GetExBindingSourceByTableName("B2");
            DataRow[] treatRecords = GetHSCTreatmentRecord(treatmentBs, DateOfTransplant);
            //All drug records for current HSCT where REASDRUG = 9 AND IDAABCCD <> NULL
            ExBindingSource drugBs = GetExBindingSourceByTableName("C3");
            const string drugFilter = "REASDRUG = 9 AND IDAABCCD IS NOT NULL";
            DataRow[] drugRecords = GetDrugRecordsForCurrentHSCT(drugBs, DateOfTransplant, RecordSelector.ALL,
                                                                 drugFilter);
            //PreCondition is :           
            //VCONDITI=2 AND (IDAABCCD>=600 and IDAABCCD<=665  and IDAABCCD<>650 and IDAABCCD<>632)
            /* is the corresponding condition for the answer 'No' */
            if (treatRecords != null)
            {
                if (treatRecords[0]["VCONDITI"].ToString() == "2")
                {
                    if (drugRecords != null)
                    {
                        for (int i = 0; i < drugRecords.Length - 1; i++)
                        {
                            int iIDAABCCD;
                            bool bIDAABCCD = int.TryParse(drugRecords[i]["IDAABCCD"].ToString(), out iIDAABCCD);
                            if (bIDAABCCD)
                            {
                                if ((int) drugRecords[i]["IDAABCCD"] >= 600
                                    && (int) drugRecords[i]["IDAABCCD"] <= 665
                                    && (int) drugRecords[i]["IDAABCCD"] != 650
                                    && (int) drugRecords[i]["IDAABCCD"] != 632)
                                {
                                    myAnswer.hasAResponse = true;
                                }
                                else
                                {
                                    myAnswer.hasAResponse = false;
                                }
                            }
                        }
                    }
                    else
                    {
                        myAnswer.hasAResponse = false; //drugRecord is null
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            return myAnswer;
        }

        //RGU 22-11-2011 (//RRA 13-10-2011 to do)
        // WMDAID DOESNT EXIST IN THE TABLE A0? WHY?
        //Up by RRA on 12-07-2011
        public static TranslationAnswer Get_UNRLTD_DNR_REG_SPEC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get N donor record for current HSCT
            ExBindingSource donorBs = GetExBindingSourceByTableName("C7");
            DataRow[] donorRecords = GetDonorRecordsForCurrentHSCT(donorBs, dateOfTransplant, RecordSelector.FIRST, "");
            //GPC2400-1-101         
            if (donorRecords != null)
            {
                if (donorRecords[0]["DONRL"].ToString() == "5" || donorRecords[0]["DONRL"].ToString() == "7" ||
                    donorRecords[0]["DONRL"].ToString() == "8")
                {
                    if (donorRecords[0]["WMDAID"].ToString() != "")
                    {
//GC2400-1-202
                        if (donorRecords[0]["WMDAID"].ToString() == "ATCB" ||
                            donorRecords[0]["WMDAID"].ToString() == "BACB"
                            || donorRecords[0]["WMDAID"].ToString() == "CLCB" ||
                            donorRecords[0]["WMDAID"].ToString() == "CN1"
                            || donorRecords[0]["WMDAID"].ToString() == "CS" ||
                            donorRecords[0]["WMDAID"].ToString() == "CSCB"
                            || donorRecords[0]["WMDAID"].ToString() == "HRCB" ||
                            donorRecords[0]["WMDAID"].ToString() == "IR"
                            || donorRecords[0]["WMDAID"].ToString() == "KRCB" ||
                            donorRecords[0]["WMDAID"].ToString() == "MXCB"
                            || donorRecords[0]["WMDAID"].ToString() == "PL6" ||
                            donorRecords[0]["WMDAID"].ToString() == "R3"
                            || donorRecords[0]["WMDAID"].ToString() == "R4" ||
                            donorRecords[0]["WMDAID"].ToString() == "SCB"
                            || donorRecords[0]["WMDAID"].ToString() == "SECB" ||
                            donorRecords[0]["WMDAID"].ToString() == "SRCB"
                            || donorRecords[0]["WMDAID"].ToString() == "TICB" ||
                            donorRecords[0]["WMDAID"].ToString() == "UNKN")
                        {
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = GetEBMTVariableValueDescription("WMDAID", 70,
                                                                                  (int) donorRecords[0]["IDAABECN"]);
                        }
                        else
                        {
                            myAnswer.hasAResponse = false;
                        }
                    }
                    else // WMDAID is NULL
                    {
                        myAnswer.hasAResponse = true;
                        myAnswer.freeTextEntry = true;
                        myAnswer.textAnswer = donorRecords[0]["DONREGID"].ToString() != "" ? donorRecords[0]["DONREGID"].ToString() : "Empty value";
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
                return myAnswer;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_SYS_SCD_INV_TYP_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");
            //Get all clinical problem record for diagnosis of the current HSCT
            ExBindingSource clinicalProblemBs = GetExBindingSourceByTableName("TDA0_CN_");
            DataRow[] clinPbmRecords = GetClinicalProblemRecordForDiagOfCurrentHSCT(clinicalProblemBs, dateOfTransplant,
                                                                                    RecordSelector.ALL, "");

            //VAUTOIM2=1   /* 1 is 'NO' */
            //IDAABECN >= 206 and IDAABECN<>210 and IDAABECN<>213 and IDAABECN<>224 and IDAABECN<>229 and IDAABECN<>233 
            //and IDAABECN<>237 and IDAABECN<>238 and IDAABECN<>239 and IDAABECN<>240 and IDAABECN<>247 and IDAABECN<>248 
            //and IDAABECN<>249 and IDAABECN<>250 and IDAABECN<>251 and IDAABECN<>269 and IDAABECN<>270 and IDAABECN<>null 
            //and DCOMPPR=1


            if (diagRecords[0]["VAUTOIM2"].ToString() == "1")
            {
                if ((int) clinPbmRecords[0]["IDAABECN"] >= 206 && (int) clinPbmRecords[0]["IDAABECN"] != 210
                    && (int) clinPbmRecords[0]["IDAABECN"] != 213 && (int) clinPbmRecords[0]["IDAABECN"] != 224
                    && (int) clinPbmRecords[0]["IDAABECN"] != 229 && (int) clinPbmRecords[0]["IDAABECN"] != 233
                    && (int) clinPbmRecords[0]["IDAABECN"] != 237 && (int) clinPbmRecords[0]["IDAABECN"] != 238
                    && (int) clinPbmRecords[0]["IDAABECN"] != 239 && (int) clinPbmRecords[0]["IDAABECN"] != 240
                    && (int) clinPbmRecords[0]["IDAABECN"] != 247 && (int) clinPbmRecords[0]["IDAABECN"] != 248
                    && (int) clinPbmRecords[0]["IDAABECN"] != 249 && (int) clinPbmRecords[0]["IDAABECN"] != 250
                    && (int) clinPbmRecords[0]["IDAABECN"] != 251 && (int) clinPbmRecords[0]["IDAABECN"] != 269
                    && (int) clinPbmRecords[0]["IDAABECN"] != 270 && clinPbmRecords[0]["IDAABECN"].ToString() != "null"
                    && clinPbmRecords[0]["IDAABECN"].ToString() != "NULL" &&
                    clinPbmRecords[0]["DCOMPPR"].ToString() == "1")
                {
                    // If IDAABECN=776 or 777 or 778 or 779 copy OTHDISCO value (table CN), 
                    //if IDAABECN= any of the other values allowed in the condition, copy IDAABECN label description.
                    int iValueCodeToCopy = (int) clinPbmRecords[0]["IDAABECN"];
                    switch ((int) clinPbmRecords[0]["IDAABECN"])
                    {
                        case 776:
                        case 777:
                        case 778:
                        case 779:
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = diagRecords[0]["OTHDISCO"].ToString();
                            break;
                        default:
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = GetEBMTVariableValueDescription("IDAABECN", 126, iValueCodeToCopy);
                            break;
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_SYS_LUP_ERY_INV_TYP_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");
            //Get all clinical problem record for diagnosis of the current HSCT
            ExBindingSource clinicalProblemBs = GetExBindingSourceByTableName("TDA0_CN_");
            DataRow[] clinPbmRecords = GetClinicalProblemRecordForDiagOfCurrentHSCT(clinicalProblemBs, dateOfTransplant,
                                                                                    RecordSelector.ALL, "");

            //VAUTOIM2=2
            //IDAABECN<>203 and IDAABECN<>204 and IDAABECN<>205 and IDAABECN<>210 and IDAABECN<>213  
            // and IDAABECN<>221 and IDAABECN<>223 and IDAABECN<>224 and IDAABECN<>225 
            //and IDAABECN<>226 and IDAABECN<>229 and IDAABECN<>230 and IDAABECN<>233 and IDAABECN<>234 and IDAABECN<>247 
            //and IDAABECN<>248 and IDAABECN<>249 and IDAABECN<>250 and IDAABECN<>251 and IDAABECN<>269 
            //and IDAABECN<>270 and IDAABECN<>null and DCOMPPR=2

            //   If IDAABECN=776 or 777 or 778 or 779 copy OTHDISCO value (table CN), 
            //if IDAABECN= any of the other values allowed in the condition, copy IDAABECN label description.
            bool isAutoImDis = diagRecords[0]["VAUTOIM2"].ToString() == "2";
            if (isAutoImDis)
            {
                if ((int) clinPbmRecords[0]["IDAABECN"] != 203 && (int) clinPbmRecords[0]["IDAABECN"] != 204 &&
                    (int) clinPbmRecords[0]["IDAABECN"] != 205
                    && (int) clinPbmRecords[0]["IDAABECN"] != 210 && (int) clinPbmRecords[0]["IDAABECN"] != 213
                    && (int) clinPbmRecords[0]["IDAABECN"] != 221 && (int) clinPbmRecords[0]["IDAABECN"] != 223
                    && (int) clinPbmRecords[0]["IDAABECN"] != 224 && (int) clinPbmRecords[0]["IDAABECN"] != 225
                    && (int) clinPbmRecords[0]["IDAABECN"] != 226 && (int) clinPbmRecords[0]["IDAABECN"] != 229 &&
                    (int) clinPbmRecords[0]["IDAABECN"] != 230
                    && (int) clinPbmRecords[0]["IDAABECN"] != 233 && (int) clinPbmRecords[0]["IDAABECN"] != 234
                    && (int) clinPbmRecords[0]["IDAABECN"] != 247 && (int) clinPbmRecords[0]["IDAABECN"] != 248
                    && (int) clinPbmRecords[0]["IDAABECN"] != 249 && (int) clinPbmRecords[0]["IDAABECN"] != 250
                    && (int) clinPbmRecords[0]["IDAABECN"] != 251 && (int) clinPbmRecords[0]["IDAABECN"] != 269
                    && (int) clinPbmRecords[0]["IDAABECN"] != 270 && clinPbmRecords[0]["IDAABECN"].ToString() != "null"
                    && clinPbmRecords[0]["IDAABECN"].ToString() != "NULL" &&
                    clinPbmRecords[0]["DCOMPPR"].ToString() == "2")
                {
                    // If IDAABECN=776 or 777 or 778 or 779 copy OTHDISCO value (table CN), 
                    //if IDAABECN= any of the other values allowed in the condition, copy IDAABECN label description.
                    int iValueCodeToCopy = (int) clinPbmRecords[0]["IDAABECN"];
                    switch ((int) clinPbmRecords[0]["IDAABECN"])
                    {
                        case 776:
                        case 777:
                        case 778:
                        case 779:
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = diagRecords[0]["OTHDISCO"].ToString();
                            break;
                        default:
                            myAnswer.hasAResponse = true;
                            myAnswer.freeTextEntry = true;
                            myAnswer.textAnswer = GetEBMTVariableValueDescription("IDAABECN", 126, iValueCodeToCopy);
                            break;
                    }
                }
                else
                {
                    myAnswer.hasAResponse = false;
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        /// <summary>
        ///   Should verify the response from selection GS2400-5-170
        /// </summary>
        /// <param name="dateOfTransplant"> </param>
        /// <returns> </returns>
        public static TranslationAnswer Get_SLE_OTR_ABDY_SPEC_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //VAUTOIM2=2
            bool isAutoImDis = diagRecords[0]["VAUTOIM2"].ToString() == "2";
            if (isAutoImDis)
            {
                //circulating antibody record for the diagnosis of the current HSCT 
                ExBindingSource circABBs = GetExBindingSourceByTableName("TDA0_CO_");
                DataRow[] circABRecords = GetCirculatingAntibodyRecordForDiagOfCurrentHSCT(circABBs, dateOfTransplant,
                                                                                           RecordSelector.FIRST);
                // and assessment record for the diagnosis of the current HSCT
                ExBindingSource assesBs = GetExBindingSourceByTableName("B4");
                DataRow[] assesRecords = GetAssesmentRecordsUntilCurrentHSCT(assesBs, dateOfTransplant,
                                                                             RecordSelector.FIRST, "");
                if (circABBs.Count > 0 && assesBs.Count > 0)
                {
                    //(IDAABECO<>60 and IDAABECO<>53 and IDAABECO<>54 and IDAABECO<>888 and IDAABECO<>null 
                    //and ATIBPRS=3) or  (ANTIBODY=1 or ANTIBODY=99)
                    if ((circABRecords[0]["IDAABECO"].ToString() != "53" &&
                         circABRecords[0]["IDAABECO"].ToString() != "54"
                         && circABRecords[0]["IDAABECO"].ToString() != "60" &&
                         circABRecords[0]["IDAABECO"].ToString() != "888"
                         && circABRecords[0]["IDAABECO"].ToString() != "null" &&
                         circABRecords[0]["IDAABECO"].ToString() != "NULL"
                         && circABRecords[0]["ATIBPRS"].ToString() == "3") ||
                        (assesRecords[0]["ANTIBODY"].ToString() == "1" || assesRecords[0]["ANTIBODY"].ToString() == "99"))
                    {
                        // If IDAABECO=777  copy ABOTH value (table CO), if IDAABECO= any of the other values allowed in the condition, copy IDAABECO label description.
                        int iValueCodeToCopy = (int) circABRecords[0]["IDAABECO"];
                        switch (circABRecords[0]["IDAABECO"].ToString())
                        {
                            case "777":
                                myAnswer.hasAResponse = true;
                                myAnswer.freeTextEntry = true;
                                myAnswer.textAnswer = circABRecords[0]["ABOTH"].ToString();
                                break;
                            default:
                                myAnswer.hasAResponse = true;
                                myAnswer.freeTextEntry = true;
                                myAnswer.textAnswer = GetEBMTVariableValueDescription("IDAABECO", 126, iValueCodeToCopy);
                                break;
                        }
                    }
                    else
                    {
                        myAnswer.hasAResponse = false;
                    }
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        public static TranslationAnswer Get_SJO_SYN_INV_TYP_value(DateTime dateOfTransplant)
        {
            //Prepare an empty TranslationAnswer object to send.
            TranslationAnswer myAnswer = new TranslationAnswer();
            //Get last diagnosis record before current HSCT
            ExBindingSource diagnosisBs = GetExBindingSourceByTableName("B1");
            DataRow[] diagRecords = GetDiagnosisRecordsBeforeHSCT(diagnosisBs, dateOfTransplant, RecordSelector.LAST, "");

            //VAUTOIM2=4
            bool isAutoImDis = diagRecords[0]["VAUTOIM2"].ToString() == "4";
            if (isAutoImDis)
            {
                //clinical problem record for the diagnosis of the current HSCT 
                ExBindingSource clinPBbs = GetExBindingSourceByTableName("TDA0_CN_");
                DataRow[] clinPBRecord = GetClinicalProblemRecordForDiagOfCurrentHSCT(clinPBbs, dateOfTransplant,
                                                                                      RecordSelector.FIRST, "");
                // and assessment record for the diagnosis of the current HSCT
                ExBindingSource assesBs = GetExBindingSourceByTableName("B4");
                if (clinPBbs.Count > 0 && assesBs.Count > 0)
                {
                    //IDAABECN<>208 and IDAABECN<>216 and IDAABECN<>217 and IDAABECN<>218 
                    //and IDAABECN<>219 and IDAABECN<>234 and IDAABECN<>247 and IDAABECN<>248
                    //and IDAABECN<>249 and IDAABECN<>250 and IDAABECN<>251 and IDAABECN<>269 
                    //and IDAABECN<>270 and IDAABECN<>null and DCOMPPR=2
                    if (clinPBRecord[0]["IDAABECN"].ToString() != "208" &&
                        clinPBRecord[0]["IDAABECN"].ToString() != "216"
                        && clinPBRecord[0]["IDAABECN"].ToString() != "217" &&
                        clinPBRecord[0]["IDAABECN"].ToString() != "218"
                        && clinPBRecord[0]["IDAABECN"].ToString() != "219" &&
                        clinPBRecord[0]["IDAABECN"].ToString() != "234"
                        && clinPBRecord[0]["IDAABECN"].ToString() != "248" &&
                        clinPBRecord[0]["IDAABECN"].ToString() != "249"
                        && clinPBRecord[0]["IDAABECN"].ToString() != "250" &&
                        clinPBRecord[0]["IDAABECN"].ToString() != "251"
                        && clinPBRecord[0]["IDAABECN"].ToString() != "269" &&
                        clinPBRecord[0]["IDAABECN"].ToString() != "270"
                        && clinPBRecord[0]["IDAABECN"].ToString() != "NULL" &&
                        clinPBRecord[0]["DCOMPPR"].ToString() == "2"
                        )
                    {
                        int iValueCodeToCopy = (int) clinPBRecord[0]["IDAABECN"];
                        switch (clinPBRecord[0]["IDAABECN"].ToString())
                        {
                            case "775":
                            case "776":
                            case "777":
                            case "778":
                            case "779":
                                myAnswer.hasAResponse = true;
                                myAnswer.freeTextEntry = true;
                                myAnswer.textAnswer = clinPBRecord[0]["OTHDISCO"].ToString();
                                break;
                            default:
                                myAnswer.hasAResponse = true;
                                myAnswer.freeTextEntry = true;
                                myAnswer.textAnswer = GetEBMTVariableValueDescription("IDAABECN", 52, iValueCodeToCopy);
                                break;
                        }
                    }
                }
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        //RGU 2400 TO DO
        public static TranslationAnswer Get_MPS_POS_JAK2_AS_IND3_value(DateTime dateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            return myAnswer;
        }

        //RRA - 2400
        public static TranslationAnswer get_ND_antigenic_value(DateTime DateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //N donor record for current HSCT
            ExBindingSource DonorBs = GetExBindingSourceByTableName("C7");
            DataRow[] donorRecords = GetDonorRecordsForCurrentHSCT(DonorBs, DateOfTransplant, RecordSelector.FIRST, "");
            bool isND = false;
            if (donorRecords != null)
            {
                //(DONRL=5 or DONRL=7 or DONRL=8) ADN MMSERA = 3
                if (donorRecords[0]["DONRL"].ToString() == "5" || donorRecords[0]["DONRL"].ToString() == "7" ||
                    donorRecords[0]["DONRL"].ToString() == "8")
                {
                    if (donorRecords[0]["MMSERA"].ToString() == "3"
                        || donorRecords[0]["MMSERB"].ToString() == "3"
                        || donorRecords[0]["MMSERC"].ToString() == "3"
                        || donorRecords[0]["MMSERDR"].ToString() == "3"
                        || donorRecords[0]["MMSERDQ"].ToString() == "3"
                        || donorRecords[0]["MMSERDP"].ToString() == "3")
                    {
                        isND = true;
                    }
                }
            }
            if (isND)
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
                myAnswer.textAnswer = "ND"; // as not done
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        //RRA - 2400
        public static TranslationAnswer get_ND_allelic_value(DateTime DateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //N donor record for current HSCT
            ExBindingSource DonorBs = GetExBindingSourceByTableName("C7");
            DataRow[] donorRecords = GetDonorRecordsForCurrentHSCT(DonorBs, DateOfTransplant, RecordSelector.FIRST, "");
            bool isND = false;
            if (donorRecords != null)
            {
                //(DONRL=5 or DONRL=7 or DONRL=8) ADN MMSERA = 3
                if (donorRecords[0]["DONRL"].ToString() == "5" || donorRecords[0]["DONRL"].ToString() == "7" ||
                    donorRecords[0]["DONRL"].ToString() == "8")
                {
                    if (donorRecords[0]["MMALLA"].ToString() == "3"
                        || donorRecords[0]["MMALLB"].ToString() == "3"
                        || donorRecords[0]["MMALLC"].ToString() == "3"
                        || donorRecords[0]["MMALLDR"].ToString() == "3"
                        || donorRecords[0]["MMALLDQ"].ToString() == "3"
                        || donorRecords[0]["MMALLDP"].ToString() == "3")
                    {
                        isND = true;
                    }
                }
            }
            if (isND)
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = false;
                myAnswer.textAnswer = "ND"; // as not done
            }
            else
            {
                myAnswer.hasAResponse = false;
            }
            return myAnswer;
        }

        /// <summary>
        ///   RGU - up by RRA - up again by RRA on 20/12/2011
        /// </summary>
        /// <param name="dateOfTransplant"> </param>
        /// <returns> </returns>
        public static TranslationAnswer Get_HSC_GH_Pro_Value(DateTime dateOfTransplant)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            //treatment record for current HSCT
            ExBindingSource treatmentBs = GetExBindingSourceByTableName("B2");
            DataRow[] treatRecords = GetTreatmentRecordForCurrentHSCT(treatmentBs, dateOfTransplant,
                                                                      RecordSelector.FIRST, "");
            //(VTRANTYP=2 and VBMSC=2 and NUMCOLL<77) or (VTRANTYP=2 and VPBSC=2 and VNUMBMOB<77)
            bool isConditionComplete;
            if (treatRecords[0]["NUMCOLL"] != DBNull.Value && treatRecords[0]["VNUMBMOB"] != DBNull.Value)
            {
                if (treatRecords[0]["VTRANTYP"].ToString() == "2" && treatRecords[0]["VBMSC"].ToString() == "2" &&
                    (int) treatRecords[0]["NUMCOLL"] < 77)
                {
                    isConditionComplete = true;
                }
                else if (treatRecords[0]["VTRANTYP"].ToString() == "2" && treatRecords[0]["VPBSC"].ToString() == "2" &&
                         (int) treatRecords[0]["VNUMBMOB"] < 77)
                {
                    isConditionComplete = true;
                }
                else
                {
                    isConditionComplete = false;
                }
            }
            else
            {
                isConditionComplete = false;
            }

            if (isConditionComplete)
            {
                //IF numcoll is null && BNUMBMOB is NULL
                //THEN SOMME = 0
                //ELSE IF NUMCOLL OR BNUMBMOB is NULL
                // IF NUMCOLL est NULL
                // SOMME = BNUMBMOB
                //ELSE SOMME = NUMCOLL
                //ELSE SOMME = NUMCOLL + BNUMBMOB
                int sum;
                if (treatRecords[0]["NUMCOLL"] == DBNull.Value &&
                    treatRecords[0]["VNUMBMOB"] == DBNull.Value)
                {
                    sum = 0;
                }
                else if (treatRecords[0]["NUMCOLL"] != DBNull.Value ||
                         treatRecords[0]["VNUMBMOB"] != DBNull.Value)
                {
                    {
                        if (treatRecords[0]["NUMCOLL"] == DBNull.Value)
                        {
                            sum = (int) treatRecords[0]["VNUMBMOB"];
                        }
                        else
                        {
                            sum = (int) treatRecords[0]["NUMCOLL"];
                        }
                    }
                }
                else
                {
                    sum = (int) treatRecords[0]["NUMCOLL"] + (int) treatRecords[0]["VNUMBMOB"];
                }
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = sum.ToString();
            }

            return myAnswer;
        }

        //from specification 12082011bak
        public static TranslationAnswer Get_HSCT_RSRCH_CNSNT_YN_value()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = "Yes";
            return myAnswer;
        }

        public static TranslationAnswer Get_thisvalue()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = false;
            return myAnswer;
        }

        public static TranslationAnswer Get_Null_value()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = "";
            return myAnswer;
        }

        #region Functions that are returning default values or picked up from settings

        public static TranslationAnswer OverrideValueTo_NO()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = "No";
            return myAnswer;
        }

        public static TranslationAnswer OverrideValueCode(string HasCorrespondance)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = String.Compare(HasCorrespondance, "Yes", StringComparison.OrdinalIgnoreCase) == 0 ? "UA" : "NA";
            return myAnswer;
        }

        public static TranslationAnswer Get_other_unit_name_specify()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = Settings.Default.Other_specify;
            return myAnswer;
        }

        public static TranslationAnswer Get_Today_Date()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = DateTime.Now.ToString("yyyy-MM-dd");
            return myAnswer;
        }

        public static TranslationAnswer Get_Contact_Firstname()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = Settings.Default.ContactFirstname;
            return myAnswer;
        }

        public static TranslationAnswer Get_Contact_Lastname()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = Settings.Default.ContactLastname;
            return myAnswer;
        }

        public static TranslationAnswer Get_Contact_PhoneNumber()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = Settings.Default.ContactPhoneNumber;
            return myAnswer;
        }

        public static TranslationAnswer Get_Contact_Fax()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = Settings.Default.ContactFax;
            return myAnswer;
        }

        public static TranslationAnswer Get_Contact_Email()
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            myAnswer.hasAResponse = true;
            myAnswer.freeTextEntry = true;
            myAnswer.textAnswer = Settings.Default.ContactEmail;
            return myAnswer;
        }

        public static TranslationAnswer Get_FollowUp_Type_Period(String proposedDuePeriod, String currentDuePeriod)
        {
            TranslationAnswer myAnswer = new TranslationAnswer();
            if (proposedDuePeriod == currentDuePeriod)
            {
                myAnswer.hasAResponse = true;
                myAnswer.freeTextEntry = true;
                myAnswer.textAnswer = proposedDuePeriod;
                return myAnswer;
            }
            myAnswer.hasAResponse = false;
            return myAnswer;
        }

        #endregion

        #endregion

        internal enum RecordSelector
        {
            ONE = 1,
            FIRST = 1,
            SECOND = 2,
            THIRD = 3,
            FOURTH = 4,
            FIFTH = 5,
            SIXTH = 6,
            SEVENTH = 7,
            EIGHTH = 8,
            NINTH = 9,
            TENTH = 10,
            ELEVEN = 11,
            TWELVE = 12,
            THIRTEENTH = 13,
            FOURTEENTH = 14,
            FIFTHEENTH = 15,
            SIXTEENTH = 16,
            SEVENTEENTH = 17,
            EIGHTEENTH = 18,
            NINETEENTH = 19,
            TWENTIETH = 20,
            LAST = 99,
            ALL = 100
        }

        #endregion
    }
}